-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSetupViewController.swift
More file actions
121 lines (82 loc) · 3.56 KB
/
SetupViewController.swift
File metadata and controls
121 lines (82 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// SetupViewController.swift
// HandWriting-Learner
//
// Created by Alban on 08.03.16.
// Copyright © 2016 Alban Perli. All rights reserved.
//
import UIKit
struct AlertTextConst {
static let kLoadAlertText = "Please give a network name"
static let kCreateAlertText = "Please setup the network correctly"
static let kAlertTitle = "Wrong Setup"
}
class SetupViewController: UIViewController {
var networkName : String!
var learningRate : String!
var momentum : String!
@IBOutlet weak var networkNameTxtField: UITextField!
@IBOutlet weak var momentumTxtField: UITextField!
@IBOutlet weak var learningRateTxtField: UITextField!
@IBAction func loadBtnClicked(_ sender: UIButton) {
if !networkNameIsEmpty() {
FFNNManager.instance.createNetworkFromFileName(self.networkName)
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))
self.present(alert, animated: true, completion: nil)
}
}
@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.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))
self.present(alert, animated: true, completion: nil)
}
}
func learningRateIsEmpty() -> Bool {
self.learningRate = learningRateTxtField.text!
guard learningRate.isEmpty else {
return false
}
return true
}
func momentumIsEmpty() -> Bool {
self.momentum = momentumTxtField.text!
guard momentum.isEmpty else {
return false
}
return true
}
func networkNameIsEmpty() -> Bool {
self.networkName = networkNameTxtField.text!
guard networkName.isEmpty else {
return false
}
return true
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
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.destination as! ViewController
vc.currentNetworkName = networkName
}
}
}