Last active
August 31, 2015 18:22
-
-
Save tmbo/98585372cc68656048e0 to your computer and use it in GitHub Desktop.
muvr-mlp-example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://github.com/CocoaPods/Specs.git' | |
platform :ios, '8.4' | |
use_frameworks! | |
pod 'MLPNeuralNet', '~> 1.0.0' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MLPNeuralNet.h" | |
// ... | |
// Load sample from file (array of double values representing the feature values) | |
NSString* samplePath = [[NSBundle mainBundle] pathForResource:@"sample" | |
ofType:@"raw"]; | |
NSData *sample = [NSData dataWithContentsOfFile:samplePath]; | |
// Load weights from file. The file is a raw file containing an array of double values | |
NSString* path = [[NSBundle mainBundle] pathForResource:@"weights" | |
ofType:@"raw"]; | |
NSData *weights = [NSData dataWithContentsOfFile:path]; | |
// Check if number of weights is correct | |
// NSUInteger numberOfWeights = [rawData length] / sizeof(double); | |
// Setup network | |
NSArray *layers = [NSArray arrayWithObjects:@1200, @500, @250, @100, @29, nil]; | |
MLPNeuralNet *model = [[MLPNeuralNet alloc] initWithLayerConfig:layers | |
weights:weights | |
outputMode:MLPClassification]; | |
model.activationFunction = MLPReLU; | |
// Predict output of the model for new sample | |
NSMutableData * prediction = [NSMutableData dataWithLength:sizeof(double)*29]; | |
[model predictByFeatureVector:sample intoPredictionVector:prediction]; | |
double * assessment = (double *)prediction.bytes; | |
for (int i = 0; i < 29; ++i) { | |
NSLog(@"Assessment %d is %f", i, assessment[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment