// // MPT_PercentilePlugin.m // MPT_GKR // // Created by Andrew Salamon on 8/27/08. // Copyright 2008 Machine Perception Laboratory, University of California San Diego.. All rights reserved. // #import "MPT_PercentilePlugin.h" //#import "MPT_MeterController.h" #import #import #import "MPT_Face.h" @implementation MPT_PercentilePlugin - (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:0]; [meter setMax:100]; [meter setCutoff:50]; [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(@"Percentile", nil, [NSBundle bundleForClass:[self class]], @""); } - (NSString *)internalName { return @"percentile"; } - (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) float z = ( [orig floatValue] - m ) / (s * c); float p = 100 / (1 + exp(-z) ); [resDict setObject:[NSNumber numberWithFloat:p] forKey:@"Percentile"]; [resDict setObject:[NSNumber numberWithFloat:[meter cutoff]] forKey:@"cutoff"]; return resDict; } return nil; } @end