Skip to content

Commit

Permalink
Finished creating SimpleLinearRegression class (which allows the use …
Browse files Browse the repository at this point in the history
…of 1 feature set and 1 set of output) and the PolynomialRegression class which allows for multiple features. The class have been tested on another example Xcode project, but unit tests will be coming soon
  • Loading branch information
Guled committed Jul 3, 2016
1 parent cac9741 commit c3c3874
Show file tree
Hide file tree
Showing 31 changed files with 7,009 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
@@ -0,0 +1,6 @@
[submodule "Carthage/Checkouts/Upsurge"]
path = Carthage/Checkouts/Upsurge
url = https://github.com/aleph7/Upsurge.git
[submodule "Carthage/Checkouts/SwiftCSV"]
path = Carthage/Checkouts/SwiftCSV
url = https://github.com/naoty/SwiftCSV.git
2 changes: 2 additions & 0 deletions Cartfile
@@ -0,0 +1,2 @@
github "aleph7/Upsurge"
github "naoty/SwiftCSV"
2 changes: 2 additions & 0 deletions Cartfile.resolved
@@ -0,0 +1,2 @@
github "naoty/SwiftCSV" "0.3.2"
github "aleph7/Upsurge" "0.7.1"
3,076 changes: 3,076 additions & 0 deletions Carthage/Build/iOS/5FD32965-4A8D-3B49-863A-52CC8CA028E9.bcsymbolmap

Large diffs are not rendered by default.

3,058 changes: 3,058 additions & 0 deletions Carthage/Build/iOS/76FBCEEB-5344-3B4C-87CE-1B427BF1FF26.bcsymbolmap

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions Carthage/Build/iOS/Upsurge.framework.dSYM/Contents/Info.plist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
99 changes: 99 additions & 0 deletions Carthage/Build/iOS/Upsurge.framework/Headers/Upsurge-Swift.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Carthage/Build/iOS/Upsurge.framework/Headers/Upsurge.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Carthage/Build/iOS/Upsurge.framework/Info.plist
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions Carthage/Build/iOS/Upsurge.framework/Modules/module.modulemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Carthage/Build/iOS/Upsurge.framework/Upsurge
Binary file not shown.
1 change: 1 addition & 0 deletions Carthage/Checkouts/SwiftCSV
Submodule SwiftCSV added at 86b491
1 change: 1 addition & 0 deletions Carthage/Checkouts/Upsurge
Submodule Upsurge added at a0393d
122 changes: 122 additions & 0 deletions DataManager.swift
@@ -0,0 +1,122 @@
//
// DataManager.swift
// MLKit
//
// Created by Guled on 6/30/16.
// Copyright © 2016 Somnibyte. All rights reserved.
//

import Foundation
import Upsurge

/**
The Numeric Type Protocol allows for generic functions
to take in integers or doubles or floats.
*/
public protocol NumericType {
func +(lhs: Self, rhs: Self) -> Self
func -(lhs: Self, rhs: Self) -> Self
func *(lhs: Self, rhs: Self) -> Self
func /(lhs: Self, rhs: Self) -> Self
func %(lhs: Self, rhs: Self) -> Self
init(_ v: Int)
}


extension Double : NumericType { }
extension Float : NumericType { }
extension Int : NumericType { }
extension Int8 : NumericType { }
extension Int16 : NumericType { }
extension Int32 : NumericType { }
extension Int64 : NumericType { }
extension UInt : NumericType { }
extension UInt8 : NumericType { }
extension UInt16 : NumericType { }
extension UInt32 : NumericType { }
extension UInt64 : NumericType { }


public class MLDataManager{


enum MLDataHandelingError: ErrorType {

}


/**
Description Goes Here
@param
@return
*/
public static func sumUpData<T: NumericType> (data: Array<T>) -> T {
var sum = T(0)
for val in data{
sum = sum + val
}
return sum
}

/**
Description Goes Here
@param
@return
*/
public static func mean<T: NumericType> (data: Array<T>) -> T {
let totalSum = sumUpData(data)
let totalAmountOfData = T(data.count)
return totalSum/totalAmountOfData
}

public static func dataToMatrix (features:[Array<Float>], output: Array<Float>) -> (Matrix<Float>,ValueArray<Float>) {


// Create Output Matrix
let output_matrix = Matrix<Float>(rows:output.count, columns: 1, elements:output)

// Create "contant/intercept" list
let contant_array = [Float](count: features[0].count, repeatedValue: 1.0)
var matrix_as_array:[[Float]] = []

for (i, _) in contant_array.enumerate() {
var new_row:[Float] = []
new_row.append(contant_array[i])

for feature_array in features {
new_row.append(feature_array[i])
}

matrix_as_array.append(new_row)
}

let feature_matrix = Matrix<Float>(matrix_as_array)

return (feature_matrix, output_matrix.elements)
}



}
















1 change: 1 addition & 0 deletions LICENSE
@@ -0,0 +1 @@
The license can be found here: https://creativecommons.org/licenses/by/4.0/

0 comments on commit c3c3874

Please sign in to comment.