Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
!*.xcworkspace/contents.xcworkspacedata

## Other
*.moved-aside
*.xcuserstate

## Sourcery
default.profraw

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

## Packages/
.build/

## CocoaPods
Pods/

## Carthage
Carthage/Build

## fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

## FBSnapshotTestCase
FailureDiffs/

## Deployment scripts
.setup_travis_deployment.sh
.match_key

## AppCode
.idea/
53 changes: 41 additions & 12 deletions HandWriting-Learner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,17 @@
B5E8EF701C84A32800D977DF /* HandWriting-Learner */ = {
isa = PBXGroup;
children = (
B5E8EF911C84A33D00D977DF /* HistoryCell */,
B5E8EFAA1C84A45A00D977DF /* NeuronalNetworkManager */,
B5E8EFA71C84A3D400D977DF /* UIImage-Extension */,
B5E8EFA41C84A35F00D977DF /* Swift-AI */,
B5E8EF911C84A33D00D977DF /* HistoryCell */,
B5E8EFA71C84A3D400D977DF /* UIImage-Extension */,
B5E8EF711C84A32800D977DF /* AppDelegate.swift */,
B50C71631C8F1BA7003D6EC1 /* SetupViewController.swift */,
B5E8EF731C84A32800D977DF /* ViewController.swift */,
B5E8EF751C84A32800D977DF /* Main.storyboard */,
B5E8EF781C84A32800D977DF /* Assets.xcassets */,
B5E8EF7A1C84A32800D977DF /* LaunchScreen.storyboard */,
B5E8EF7D1C84A32800D977DF /* Info.plist */,
B5E8EF7A1C84A32800D977DF /* LaunchScreen.storyboard */,
B5E8EF751C84A32800D977DF /* Main.storyboard */,
B50C71631C8F1BA7003D6EC1 /* SetupViewController.swift */,
B5E8EF731C84A32800D977DF /* ViewController.swift */,
);
path = "HandWriting-Learner";
sourceTree = "<group>";
Expand All @@ -174,7 +174,7 @@
children = (
B5E8EF921C84A34600D977DF /* HistoryTableViewCell.swift */,
);
name = HistoryCell;
path = HistoryCell;
sourceTree = "<group>";
};
B5E8EFA41C84A35F00D977DF /* Swift-AI */ = {
Expand All @@ -184,28 +184,28 @@
B5E8EF951C84A35A00D977DF /* FFNN.swift */,
B5E8EF961C84A35A00D977DF /* Matrix.swift */,
B5E8EF971C84A35A00D977DF /* Operations.swift */,
B5E8EF981C84A35A00D977DF /* Random.swift */,
B5E8EF991C84A35A00D977DF /* README.md */,
B5E8EF981C84A35A00D977DF /* Random.swift */,
B5E8EF9A1C84A35A00D977DF /* Storage.swift */,
B5E8EF9B1C84A35A00D977DF /* Vector.swift */,
);
name = "Swift-AI";
path = "Swift-AI";
sourceTree = "<group>";
};
B5E8EFA71C84A3D400D977DF /* UIImage-Extension */ = {
isa = PBXGroup;
children = (
B5E8EFA51C84A3AF00D977DF /* UIImage+Processing.swift */,
);
name = "UIImage-Extension";
path = "UIImage-Extension";
sourceTree = "<group>";
};
B5E8EFAA1C84A45A00D977DF /* NeuronalNetworkManager */ = {
isa = PBXGroup;
children = (
B5E8EFA81C84A45700D977DF /* FFNNManager.swift */,
);
name = NeuronalNetworkManager;
path = NeuronalNetworkManager;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -253,14 +253,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0910;
ORGANIZATIONNAME = "Alban Perli";
TargetAttributes = {
B5E8EF6D1C84A32800D977DF = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 0910;
};
B5E8EF811C84A32800D977DF = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 0910;
TestTargetID = B5E8EF6D1C84A32800D977DF;
};
};
Expand Down Expand Up @@ -363,6 +365,7 @@
B5E8EF761C84A32800D977DF /* Base */,
);
name = Main.storyboard;
path = .;
sourceTree = "<group>";
};
B5E8EF7A1C84A32800D977DF /* LaunchScreen.storyboard */ = {
Expand All @@ -371,6 +374,7 @@
B5E8EF7B1C84A32800D977DF /* Base */,
);
name = LaunchScreen.storyboard;
path = .;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
Expand All @@ -384,13 +388,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -428,13 +440,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -453,6 +473,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -465,6 +486,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.alban-perli.HandWriting-Learner";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -476,6 +499,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.alban-perli.HandWriting-Learner";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -487,6 +512,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.alban-perli.HandWriting-LearnerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HandWriting-Learner.app/HandWriting-Learner";
};
name = Debug;
Expand All @@ -499,6 +526,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.alban-perli.HandWriting-LearnerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HandWriting-Learner.app/HandWriting-Learner";
};
name = Release;
Expand Down
25 changes: 1 addition & 24 deletions HandWriting-Learner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class HistoryTableViewCell: UITableViewCell {
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class FFNNManager: NSObject {
// Initialize neural network with pre-trained weights (may need to change activation function if yours was trained with a different one)
var network:FFNN?

func createNetwork(inputs: Int, hidden: Int, outputs:Int, learningRate: Float, momentum:Float){
func createNetwork(_ inputs: Int, hidden: Int, outputs:Int, learningRate: Float, momentum:Float){
// Initialize neural network with pre-trained weights (may need to change activation function if yours was trained with a different one)
network = FFNN(inputs: inputs, hidden:hidden , outputs: outputs, learningRate: learningRate, momentum: momentum, weights:nil, activationFunction: .Sigmoid, errorFunction: .Default(average: false))
network = FFNN(inputs: inputs, hidden:hidden , outputs: outputs, learningRate: learningRate, momentum: momentum, weights:nil, activationFunction: .Sigmoid, errorFunction: .default(average: false))

}

func createNetworkFromFileName(fileName:String){
func createNetworkFromFileName(_ fileName:String){
network = FFNN.fromFile(fileName)
}

func trainNetwork(inputs:[Float],answer:[Float], epoch:Int)->(output:[Float],error:Float){
func trainNetwork(_ inputs:[Float],answer:[Float], epoch:Int)->(output:[Float],error:Float){

guard network != nil else {
return ([],-1.0)
Expand All @@ -40,7 +40,7 @@ class FFNNManager: NSObject {

}

func predictionForInput(input:[Float])->[Float]{
func predictionForInput(_ input:[Float])->[Float]{
return try! network!.update(inputs: input)
}

Expand All @@ -49,11 +49,11 @@ class FFNNManager: NSObject {
return network!.getWeights()
}

func setNewWeight(weights:[Float]){
func setNewWeight(_ weights:[Float]){
try! network!.resetWithWeights(weights)
}

func saveNetworkWithName(name:String){
func saveNetworkWithName(_ name:String){
FFNNManager.instance.network?.writeToFile(name)
}

Expand Down
24 changes: 12 additions & 12 deletions HandWriting-Learner/SetupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ class SetupViewController: UIViewController {
@IBOutlet weak var momentumTxtField: UITextField!
@IBOutlet weak var learningRateTxtField: UITextField!

@IBAction func loadBtnClicked(sender: UIButton) {
@IBAction func loadBtnClicked(_ sender: UIButton) {

if !networkNameIsEmpty() {
FFNNManager.instance.createNetworkFromFileName(self.networkName)
self.performSegueWithIdentifier("toNetwork", sender: self)
self.performSegue(withIdentifier: "toNetwork", sender: self)
}else{
let alert = UIAlertController(title: AlertTextConst.kAlertTitle, message: AlertTextConst.kLoadAlertText, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
let alert = UIAlertController(title: AlertTextConst.kAlertTitle, message: AlertTextConst.kLoadAlertText, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))

self.presentViewController(alert, animated: true, completion: nil)
self.present(alert, animated: true, completion: nil)
}

}

@IBAction func newNetworkBtnClicked(sender: AnyObject) {
@IBAction func newNetworkBtnClicked(_ sender: AnyObject) {

if !networkNameIsEmpty()
&& !learningRateIsEmpty()
&& !momentumIsEmpty() {

FFNNManager.instance.createNetwork(30*30, hidden: 601, outputs: 4, learningRate: Float(learningRate)!, momentum: Float(momentum)!)
self.performSegueWithIdentifier("toNetwork", sender: self)
self.performSegue(withIdentifier: "toNetwork", sender: self)

}else{

let alert = UIAlertController(title: AlertTextConst.kAlertTitle, message: AlertTextConst.kCreateAlertText, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
let alert = UIAlertController(title: AlertTextConst.kAlertTitle, message: AlertTextConst.kCreateAlertText, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))

self.presentViewController(alert, animated: true, completion: nil)
self.present(alert, animated: true, completion: nil)
}

}
Expand Down Expand Up @@ -104,13 +104,13 @@ class SetupViewController: UIViewController {
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.

if segue.identifier == "toNetwork"{

let vc : ViewController = segue.destinationViewController as! ViewController
let vc : ViewController = segue.destination as! ViewController
vc.currentNetworkName = networkName

}
Expand Down
Loading