def scale_neg_1_to_1_with_zero_mean_log_abs_max(v):
	'''
	!!! not working
	'''
	df = pd.DataFrame({'v':v,
	                   'sign': (v > 0) * 2 - 1})
	df['lg'] = np.log(np.abs(v)) / np.log(1.96)
	df['exclude'] = (np.isinf(df.lg) | np.isneginf(df.lg))
	for mask in [(df['sign'] == -1) & (df['exclude'] == False),
	             (df['sign'] == 1) & (df['exclude'] == False)]:
		df[mask]['lg'] = df[mask]['lg'].max() - df[mask]['lg']
	df['lg'] *= df['sign']
	df['lg'] = df['lg'].fillna(0)
	print(df[df['exclude']]['lg'].values)
	#to_rescale = convention_df['lg'].reindex(v.index)
	df['to_out'] =  scale_neg_1_to_1_with_zero_mean_abs_max(df['lg'])
	print('right')
	print(df.sort_values(by='lg').iloc[:5])
	print(df.sort_values(by='lg').iloc[-5:])
	print('to_out')
	print(df.sort_values(by='to_out').iloc[:5])
	print(df.sort_values(by='to_out').iloc[-5:])
	print(len(df), len(df.dropna()))
	return df['to_out']
def scale_neg_1_to_1_with_zero_mean_log_abs_max ( v ) : df = pd . DataFrame ( { 'v' : v , 'sign' : ( v > 0 ) * 2 - 1 } ) df [ 'lg' ] = np . log ( np . abs ( v ) ) / np . log ( 1.96 ) df [ 'exclude' ] = ( np . isinf ( df . lg ) | np . isneginf ( df . lg ) ) for mask in [ ( df [ 'sign' ] == - 1 ) & ( df [ 'exclude' ] == False ) , ( df [ 'sign' ] == 1 ) & ( df [ 'exclude' ] == False ) ] : df [ mask ] [ 'lg' ] = df [ mask ] [ 'lg' ] . max ( ) - df [ mask ] [ 'lg' ] df [ 'lg' ] *= df [ 'sign' ] df [ 'lg' ] = df [ 'lg' ] . fillna ( 0 ) print ( df [ df [ 'exclude' ] ] [ 'lg' ] . values ) df [ 'to_out' ] = scale_neg_1_to_1_with_zero_mean_abs_max ( df [ 'lg' ] ) print ( 'right' ) print ( df . sort_values ( by = 'lg' ) . iloc [ : 5 ] ) print ( df . sort_values ( by = 'lg' ) . iloc [ - 5 : ] ) print ( 'to_out' ) print ( df . sort_values ( by = 'to_out' ) . iloc [ : 5 ] ) print ( df . sort_values ( by = 'to_out' ) . iloc [ - 5 : ] ) print ( len ( df ) , len ( df . dropna ( ) ) ) return df [ 'to_out' ]
!!! not working