code: Goal thresholds
This commit is contained in:
		@ -35,7 +35,7 @@ def main(args):
 | 
				
			|||||||
  '''
 | 
					  '''
 | 
				
			||||||
    Load data
 | 
					    Load data
 | 
				
			||||||
  '''
 | 
					  '''
 | 
				
			||||||
  # Get consumption data from previous parsing
 | 
					  # Get consumption data [timestamp, consumption] from previous parsing
 | 
				
			||||||
  cons_data = lmdk_lib.load_data(args, 'cons')
 | 
					  cons_data = lmdk_lib.load_data(args, 'cons')
 | 
				
			||||||
  if cons_data.size == 0:
 | 
					  if cons_data.size == 0:
 | 
				
			||||||
    # Consumption [dt, hr, kwh]
 | 
					    # Consumption [dt, hr, kwh]
 | 
				
			||||||
@ -61,6 +61,37 @@ def main(args):
 | 
				
			|||||||
      print('[Error: %s]' %(e))
 | 
					      print('[Error: %s]' %(e))
 | 
				
			||||||
    # Save to results
 | 
					    # Save to results
 | 
				
			||||||
    lmdk_lib.save_data(args, np.array(cons, np.float32), 'cons')
 | 
					    lmdk_lib.save_data(args, np.array(cons, np.float32), 'cons')
 | 
				
			||||||
 | 
					  '''
 | 
				
			||||||
 | 
					    Find thresholds for goals.
 | 
				
			||||||
 | 
					    0.2: 0.30
 | 
				
			||||||
 | 
					    0.4: 0.23
 | 
				
			||||||
 | 
					    0.6: 0.15
 | 
				
			||||||
 | 
					    0.8: 0.13
 | 
				
			||||||
 | 
					  '''
 | 
				
			||||||
 | 
					  # {goal: theta}
 | 
				
			||||||
 | 
					  lmdk = {}
 | 
				
			||||||
 | 
					  # Percentage of landmarks
 | 
				
			||||||
 | 
					  goal = [.2, .4, .6, .8]
 | 
				
			||||||
 | 
					  # Find max consumpton to start from
 | 
				
			||||||
 | 
					  theta = max(cons_data[:, 1])
 | 
				
			||||||
 | 
					  cons_data_cur = np.copy(cons_data)
 | 
				
			||||||
 | 
					  # Find thetas for each goal
 | 
				
			||||||
 | 
					  for g in goal:
 | 
				
			||||||
 | 
					    print('Looking for %.1f... ' %(g), end='', flush=True)
 | 
				
			||||||
 | 
					    while theta > 0:
 | 
				
			||||||
 | 
					      # Reduce threshold gradually
 | 
				
			||||||
 | 
					      theta -= .01
 | 
				
			||||||
 | 
					      # Find data below the current theta
 | 
				
			||||||
 | 
					      cons_data_cur = cons_data_cur[cons_data_cur[:, 1] < theta]
 | 
				
			||||||
 | 
					      # Calculate the percentage of landmarks
 | 
				
			||||||
 | 
					      diff = (len(cons_data) - len(cons_data_cur))/len(cons_data)
 | 
				
			||||||
 | 
					      # Check if it is close enough to what we need
 | 
				
			||||||
 | 
					      if abs(diff - g)/g < .05:
 | 
				
			||||||
 | 
					        print('%.2f' %(theta))
 | 
				
			||||||
 | 
					        lmdk[g] = theta
 | 
				
			||||||
 | 
					        # Continue with the next goal
 | 
				
			||||||
 | 
					        break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
'''
 | 
					'''
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user