Untitled

mail@pastecode.io avatar
unknown
python
a year ago
12 kB
2
Indexable
def mining(global_list,minutil,hup):
  
  conditional_item_Obj = {}
  #print("** mining gl *** \n",global_list.keys())
  # for each dui in GL
  for item in global_list.keys():
    
    #print("for item in mining ",item,"utility ",global_list[item].utility,"remaining utility ",global_list[item].remainingUtility)
    
    
    # check if item is an hup
    if global_list[item].utility + global_list[item].remainingUtility >= minutil:
      if global_list[item].utility >= minutil:
        hup.append(itemset_list + [item])
      #else: continue
      '''
      #itemset_list.append(item) # prefix
      # create conditional dui item
      conditional_item = itemset(itemset_list+[item]) # {_D}
      print("conditional_item ",conditional_item.itemsetname)
      conditional_item.utility = global_list[item].utility
      conditional_item.nextItemList = global_list[item].nextItemList
      conditional_item.nextItemUtilityList = global_list[item].nextItemUtilityList
      conditional_item_Obj[str(itemset_list+[item]).strip("[]")] = conditional_item
      '''
      # for each entry e in cdui(x)
      for i in range(len(global_list[item].nextItemList)):
        #if global_list[item].nextItemList[i] == None:
        # create new entry into cdui(x )
        #conditional_item.nextItemList.append(global_list[item].nextItemList[i])
        #conditional_item.nextItemUtilityList = np.
        # for each entry connected to e 
        if global_list[item].nextItemList[i] is  None: continue
        nextItemListIndex = global_list[item].nextItemList[i][1]
        nextItem = global_list[item].nextItemList[i][0]  # c
        if global_list[item].utility + itemObjRef[nextItem].nextItemUtilityList[nextItemListIndex] >= minutil:
          # if remaining util negative , cont
          if global_list[item].remainingUtility - itemObjRef[nextItem].nextItemUtilityList[nextItemListIndex]<0: continue
          itemli = itemStrToList(item)
          conditional_item_Obj[item+"-"+str(nextItem)] = itemset(itemli+[nextItem],0,0)
          #print(global_list[item].nextItemUtilityList,global_list[item].fuzzy_utility_list)
          glItmeutility =  global_list[item].nextItemUtilityList[i]/global_list[item].fuzzy_utility_list[i]
          nextItemUtil = itemObjRef[nextItem].nextItemUtilityList[nextItemListIndex]/itemObjRef[nextItem].fuzzy_utility_list[nextItemListIndex]
          minfuzz = min(global_list[item].fuzzy_utility_list[i],itemObjRef[nextItem].fuzzy_utility_list[nextItemListIndex])
          conditional_item_Obj[item+"-"+str(nextItem)].utility = minfuzz*(glItmeutility + nextItemUtil)
          #print("conditional_item_Obj[item+-+str(nextItem)] ",conditional_item_Obj[item+"-"+str(nextItem)].itemsetname," utility ",conditional_item_Obj[item+"-"+str(nextItem)].utility)
          conditional_item_Obj[item+"-"+str(nextItem)].remainingUtility = global_list[item].remainingUtility - itemObjRef[nextItem].nextItemUtilityList[nextItemListIndex]
          conditional_item_Obj[item+"-"+str(nextItem)].nextItemList = itemObjRef[nextItem].nextItemList[nextItemListIndex:]
          conditional_item_Obj[item+"-"+str(nextItem)].nextItemUtilityList = itemObjRef[nextItem].nextItemUtilityList[nextItemListIndex:]
          conditional_item_Obj[item+"-"+str(nextItem)].fuzzy_utility_list = itemObjRef[nextItem].fuzzy_utility_list[nextItemListIndex:]
        '''
        while global_list[nextItem].nextItemList[nextItemListIndex] != None:
          # if cdui list for x exist in cdui list :
          if conditional_item.itemsetname+ [nextItem] not in conditional_item_list:
            conditional_item_list.append(conditional_item.itemsetname+ [nextItem])  
            # DA
            conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")] = itemset(conditional_item.itemsetname+ [nextItem],0,0)
          # insert new item in DA
          print(" Da ",conditional_item.itemsetname+ [nextItem])
          conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemList.append(global_list[nextItem].nextItemList[nextItemListIndex])  # next item C
          if conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemUtilityList == None:
            conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemUtilityList = np.array([global_list[nextItem].nextItemUtilityList[nextItemListIndex]+global_list[item].nextItemUtilityList[i]])
          else:
            conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemUtilityList = np.append(conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem])].nextItemUtilityList,global_list[nextItem].nextItemUtilityList[nextItemListIndex]+global_list[item].nextItemUtilityList[i])
          # update DU value of CDUI x
          conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].utility += global_list[nextItem].nextItemUtilityList[nextItemListIndex]+global_list[item].nextItemUtilityList[i]
          # update next item index
          nextItemListIndex = global_list[nextItem].nextItemList[nextItemListIndex][1]
          nextItem = global_list[nextItem].nextItemList[nextItemListIndex][0]
          if global_list[nextItem].nextItemList[nextItemListIndex] == None:
            if conditional_item.itemsetname+ [nextItem] not in conditional_item_list:
              conditional_item_list.append(conditional_item.itemsetname+ [nextItem])  
              # DA
              conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")] = itemset(conditional_item.itemsetname+ [nextItem],0,0)
              # insert new item in DA
              print(" Da ",conditional_item.itemsetname+ [nextItem])
              conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemList.append(None)  # next item C
              if conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemUtilityList == None:
                conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemUtilityList = np.array([global_list[nextItem].nextItemUtilityList[nextItemListIndex]+global_list[item].nextItemUtilityList[i]])
              else:
                conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemUtilityList = np.append(conditional_item_Obj[str(conditional_item.itemsetname+ [nextItem]).strip("[]")].nextItemUtilityList,global_list[nextItem].nextItemUtilityList[nextItemListIndex]+global_list[item].nextItemUtilityList[i])
            
            

        #update dru value
        for key in conditional_item_Obj.keys():
          
          if str(conditional_item.itemsetname).strip("[]") in key:
            if conditional_item_Obj[key.strip("[]")].nextItemList[0]!= None:
              conditional_item_Obj[key.strip("[]")].remainingUtility+=global_list[conditional_item_Obj[key.strip("[]")].nextItemList[0][0]].nextItemUtilityList[conditional_item_Obj[key.strip("[]")].nextItemList[0][1]]
            print("dru for ",key," is ",conditional_item_Obj[key.strip("[]")].remainingUtility)
      
        break
      conditional_item_Obj.pop(str(itemset_list+[item]).strip("[]"))
      '''
      if len(conditional_item_Obj)>0:
        #print("mining recur \n cond item ",conditional_item_Obj.keys(),"\n")

        mining(conditional_item_Obj,minutil,hup)
        conditional_item_Obj = {}
  #print("returning ")      
    #break
#itemObjRef[(0,0)] = a,0 obj
def mining_start(itemObjRef,minutil,hup):
  conditional_item_Obj = {}
  for item in itemObjRef.keys():
    #print(" for item ",item,"utility ",itemObjRef[item].utility," remaining utility ",itemObjRef[item].remainingUtility)
    if itemObjRef[item].utility + itemObjRef[item].remainingUtility >= minutil:
      if itemObjRef[item].utility >= minutil:
        hup.append([item])
      else : continue
      #print(" doing mining for ",item)
      for i in range(len(itemObjRef[item].nextItemList)):
        if itemObjRef[item].nextItemList[i] is  None: continue
        nextItemListIndex = itemObjRef[item].nextItemList[i][1]
        nextItem = itemObjRef[item].nextItemList[i][0]  # A
        while nextItem is not None:
          if str(item)+"-"+str(nextItem) not in conditional_item_Obj.keys():
              # DA
              #print(" da ",str(item)+"-"+str(nextItem))
              itemUtil = itemObjRef[item].nextItemUtilityList[i]/itemObjRef[item].fuzzy_utility_list[i]
              nextItemUtil = itemObjRef[nextItem].nextItemUtilityList[nextItemListIndex]/itemObjRef[nextItem].fuzzy_utility_list[nextItemListIndex]

              minfuzz = min(itemObjRef[item].fuzzy_utility_list[i],itemObjRef[nextItem].fuzzy_utility_list[nextItemListIndex])
              conditional_item_Obj[str(item)+"-"+str(nextItem)] = itemset([item]+[nextItem],minfuzz*(itemUtil+nextItemUtil),0)
              #print(" da ",str(item)+"-"+str(nextItem)," cond obj ",conditional_item_Obj[str(item)+"-"+str(nextItem)].itemsetname)
          
          prevItem  = nextItem #a
          prevItemIndex = nextItemListIndex
          if itemObjRef[nextItem].nextItemList[nextItemListIndex] is None:
            conditional_item_Obj[str(item)+"-"+str(nextItem)].nextItemList.append(None)
            if conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList is not None:
              conditional_item_Obj[str(item)+"-"+str(prevItem)].fuzzy_utility_list.append(minfuzz)
              conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList = np.append(conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList,itemObjRef[prevItem].nextItemUtilityList[prevItemIndex]+itemObjRef[item].nextItemUtilityList[i])
            else:
              conditional_item_Obj[str(item)+"-"+str(prevItem)].fuzzy_utility_list =[minfuzz]
              conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList = np.array([itemObjRef[prevItem].nextItemUtilityList[prevItemIndex]+itemObjRef[item].nextItemUtilityList[i]])
            
            #print(" conditional item ",conditional_item_Obj[str(item)+"-"+str(prevItem)].itemsetname," next item ",conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemList," next item utility ",conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList)
            break
          else:
            nextItemListIndex = itemObjRef[prevItem].nextItemList[prevItemIndex][1]
            nextItem = itemObjRef[prevItem].nextItemList[prevItemIndex][0] #c
            conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemList.append([nextItem,nextItemListIndex])  # next item C
            if conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList is None:
              conditional_item_Obj[str(item)+"-"+str(prevItem)].fuzzy_utility_list =[minfuzz]
              conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList = np.array([itemObjRef[prevItem].nextItemUtilityList[prevItemIndex]+itemObjRef[item].nextItemUtilityList[i]])
            else:
              conditional_item_Obj[str(item)+"-"+str(prevItem)].fuzzy_utility_list.append(minfuzz)
              conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList = np.append(conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList,itemObjRef[prevItem].nextItemUtilityList[prevItemIndex]+itemObjRef[item].nextItemUtilityList[i])
            #print(" conditional item ",conditional_item_Obj[str(item)+"-"+str(prevItem)].itemsetname," next item ",conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemList," next item utility ",conditional_item_Obj[str(item)+"-"+str(prevItem)].nextItemUtilityList)
        
        #update dru
        for key in conditional_item_Obj.keys():
            
          if conditional_item_Obj[key].nextItemList[0]!= None:
            conditional_item_Obj[key].remainingUtility+=itemObjRef[conditional_item_Obj[key.strip("[]")].nextItemList[0][0]].nextItemUtilityList[conditional_item_Obj[key].nextItemList[0][1]]
          #print("dru for ",key," is ",conditional_item_Obj[key.strip("[]")].remainingUtility)
        
          #if nextItem == None:
      #print("mining 2 itemsets : ,",conditional_item_Obj.keys())
      mining(conditional_item_Obj,minutil,hup)
      conditional_item_Obj = {}
      #break # do for 1 trx
    #break