// // MPT_OddsPlugin.m // // Created by Andrew Salamon on 8/27/08. // Copyright 2008 Machine Perception Laboratory, University of California San Diego.. All rights reserved. // #import "MPT_OddsPlugin.h" //#import "MPT_MeterController.h" #import #import #import "MPT_Face.h" float f( float p1, float p2, float p3 ); @implementation MPT_OddsPlugin - (id)initWithBundle:(NSBundle *)_bundle { if( self = [super initWithBundle:_bundle] ) { weights = [[NSArray alloc] initWithContentsOfFile:[_bundle pathForResource:@"weights" ofType:@"plist"]]; meter = [[MPT_MeterController alloc] init]; [meter setMin:-5]; [meter setMax:5]; [meter setCutoff:1]; [meter setLabel:[self localizedName]]; [self setView:[meter auView] forLabel:[[self labels] objectAtIndex:0]]; } return self; } - (id)copyWithZone:(NSZone *)zone { return nil; } - (void)dealloc { [super dealloc]; } - (void)awakeFromNib { [self initViews]; } - (NSString *)step { return MPT_PluginStep_Results; } - (int)sortOrder { return 15; } - (NSString *)localizedName { return NSLocalizedStringFromTableInBundle(@"Odds", nil, [NSBundle bundleForClass:[self class]], @""); } - (NSString *)internalName { return @"odds"; } - (NSView *)prefPane { return prefView; } - (void)setView:(MPT_AUView *)newView forLabel:(NSString *)label { [super setView:newView forLabel:label]; } - (void)pluginsFinishedLoading:(NSArray *)plugins { } - (NSMutableDictionary *)processResults:(NSDictionary *)results usingController:(id)controller { BOOL faceFound = ([[results objectForKey:@"CERT.faces"] count] > 0); if( faceFound ) { id enj = [results objectForKey:@"com.mpt4u.plugins.Enjoyment"]; if( ![enj isKindOfClass:[NSDictionary class]] ) { NSLog( @"Unexpected result types for Enjoyment in Percentile Plugin." ); return nil; } NSNumber *orig = [enj objectForKey:@"Enjoyment"]; if( !orig ) { NSLog( @"Missing results for Enjoyment in Percentile Plugin." ); return nil; } NSMutableDictionary *resDict = [NSMutableDictionary dictionary]; // const float m = -2.2823; // const float s = 1.1947; const float c = 0.9772; // sqrt(3/pi) const float m1 = -1.3201; const float s1 = 1.0186; const float m2 = -2.5127; const float s2 = 1.1164; float x = [orig floatValue]; float z = f( x, m1, s1*c ) / f( x, m2, s2*c ); if (z < 1) z = - 1 / z; [resDict setObject:[NSNumber numberWithFloat:z] forKey:@"Odds"]; [resDict setObject:[NSNumber numberWithFloat:[meter cutoff]] forKey:@"cutoff"]; return resDict; } return nil; } float f( float p1, float p2, float p3 ) { float numerator = exp( - (p1 - p2) / p3 ); float denominator = ( (1 + numerator) * (1 + numerator) ) * p3; return numerator / denominator; } /* if (z > 1) odds = z if(z <1) odds = - 1/z where z = f(x, m1, s1*c)/f(x, m2,s2*c) x is the output of the current asap prototype, and the function f is defined as follows f(p1, p2, p3) = numerator/denominator where numerator = exp( - ( p1 - p2)/p3) denominator = ((1+numerator)^2) *p3; */ @end