Giter VIP home page Giter VIP logo

aitoolbox's Introduction

AIToolbox

A toolbox of AI modules written in Swift: Graphs/Trees, Linear Regression, Support Vector Machines, Neural Networks, PCA, KMeans, Genetic Algorithms, MDP, Mixture of Gaussians, Logistic Regression

This framework uses the Accelerate library to speed up computations, except the Linux package versions. Written for Swift 3.0. Earlier versions are Swift 2.2 compatible

SVM ported from the public domain LIBSVM repository See https://www.csie.ntu.edu.tw/~cjlin/libsvm/ for more information

The Metal Neural Network uses the Metal framework for a Neural Network using the GPU. While it works in preliminary testing, more work could be done with this class

Use the XCTest files for examples on how to use the classes

Playgrounds for Linear Regression, SVM, and Neural Networks are available. Now available in both macOS and iOS versions.

###New - Convolution Program For the Deep Network classes, please look at the Convolution project that uses the AIToolbox library to do image recognition.

New Swift Package - Mac and Linux compatible!

The package is a sub-set of the full framework. Classes that require GCD or LAPACK have not been ported. I am investigating LAPACK on Linux alternatives, and may someday figure out how to get libdispatch to compile on Ubuntu... Use this subdirectory to reference the package from your code.

Manual

I have started a manual for the framework. It is a work-in-progress, but adds some useful explanation to pieces of the framework. All protocols, structures, and enumerations are well defined. Class descriptions are there, but not class variables and methods.

Classes/Algorithms supported:

Graphs/Trees
    Depth-first search
    Breadth-first search
    Hill-climb search
    Beam Search
    Optimal Path search

Alpha-Beta (game tree)

Genetic Algorithms
    mutations
    mating
    integer/double alleles

Constraint Propogation
    i.e. 3-color map problem

Linear Regression
    arbitrary function in model
    regularization can be used
    convenience constructor for standard polygons
    Least-squares error

Non-Linear Regression
    parameter-delta
    Gradient-Descent
    Gauss-Newton

Logistic Regression
    Use any non-linear solution method
    Multi-class capability

Neural Networks
    multiple layers, several non-linearity models
    on-line and batch training
    feed-forward or simple recurrent layers can be mixed in one network
    simple network training using GPU via Apple's Metal
    LSTM network layer implemented - needs more testing
    gradient check routines

Support Vector Machine
    Classification
    Regression
    More-than-2 classes classification

K-Means
    unlabelled data grouping

Principal Component Analysis
    data dimension reduction

Markov Decision Process
    value iteration
    policy iteration
    fitted value iteration for continuous state MDPs - uses any Regression class for fit
            (see my MDPRobot project on github for an example use)
    Monte-Carlo (every-visit, and first-visit)
    SARSA

Gaussians
    Single variable
    Multivariate - with full covariance matrix or diagonal only

Mixture Of Gaussians
    Learn density function of a mixture of gaussians from data
    EM algorithm to converge model with data

Validation
    Use to select model or parameters of model
    Simple validation (percentage of data becomes test data)
    N-Fold validation

Deep-Network
    Convolution layers
    Pooling layers
    Fully-connected NN layers
    multi-threaded

Plotting
    NSView based MLView for displaying regression data, classification data, functions, and classifier areas!
    UIView based MLView for iOS applications, same as NSView based for macOS

Regression Plot Image Classification Plot Image

License

This framework is made available with the Apache license.

Contributions

See the contribution document for information on contributing to this framework

aitoolbox's People

Contributors

alexsosn avatar hariseldon78 avatar kevincoble avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aitoolbox's Issues

Crossplattform/Linux-Support?

It would be great if there would be a package/version/branch which we can use with Open Swift projects. For example a server with vapor and the AIToolbox could be a great project. Any thoughts on this?

Contribution list / checklist

Hey!
I came across this project and was wondering if you guys could build a checklist of TODOs etc for potential contributors.

Something like

  • Benchmarks
  • CNNs
  • POMDPs
    ..etc?

Error in SVM classify

The function classify in the classifier extension of the SVM model by default always throws an error. This is due to a simple logical error in line 128. For type checking, rather than a logical OR, I believe it should be a logical AND.

load model with not plist file

When creating SVM init by function
public init?(loadFrom path: String)
svm is nil. because file model is not plist

how to create svm model by other model file (attach file)?
model.zip

Thanks!

Incremental Learning

Hi @KevinCoble,

I got a thing to ask about incremental learning which i guess you have already known. So i dont know if this library support that idea or not?

If yes, how can i use it? and which Algorithm is capable of doing so? As far as i know, this issue is really complicated so i am not too sure, however there is SVM with linear kernel that can do this thing.

If no, Do you intend to make that as a feature in the future? Cause it seems relearn every time is not a really good way to do.

Btw, if i want to check for the Precision, F-score, Recall and Accuracy and Validation how can i do that? I looked at the Test for Validation but it only showed the example for Regression so i dont know for sure.

Thank for your help again @KevinCoble

Example/Manual for Deep Convolutional Neural Net

Would it be possible to add in an example/manual section for Deep Convolutional Neural Networks? I haven't seen any documentation for this, except for having to look through the source code itself, to understand how this works.

Decision tree

Is there support for decision trees in terms of training and inference? If not, any advice on how it might be done with objective-C or Swift?

Possible to set Regularisation Strength in LogisticRegression

Firstly, This is amazing!. Thank you very much for this beautiful library.

I've only just started exploring it for the last 6 hours so apologies if this is obvious but I wanted to check it was / wasn't possible to set regularisation strength for LogisticRegression? Or perhaps I'm just invoking it incorrectly: https://gist.github.com/AJamesPhillips/07471da4b4be0190d8e34bf357c3c431

There are two tests with similar data (1 st input dimension uniform random distribution, 2 nd input dimension linear trend from 0 to 99, output dimension 0 if 2nd input dimension < 50 else 1).
On the first small data test, the classifier usually predicts an output value of 1.
On the second larger similar data set the tests fail randomly (I assume this is just overfitting).

Many thanks! (and apologies if this is a stupid question, I'm new to this area in general, both swift and classifiers etc).

Can't use framework

I'm working with MacOSx XCode 8.3.2

I noticed when AIToolbox was built, the framworks are in /Users/brianbabiak/Library/Developer/Xcode/DerivedData/AIToolbox-duqowxslltlzkpbbwvhorgzsgvwf/Build/Products/Debug

I add the framework in another project, but import AIToolbox doesn't work. All instructions followed. Any ideas?

SVM Training for one-class-svm doesn't work

When creating a One-Class SVM classifier (e.g. for the following data)
do {
try trainData.addDataPoint(input: [0.2, 0.9], dataClass:1)
try trainData.addDataPoint(input: [0.8, 0.3], dataClass:1)
try trainData.addDataPoint(input: [0.5, 0.6], dataClass:1)
} //catch etc.
let svm = SVMModel(problemType: .oneClassSVM, kernelSettings:
KernelParameters(type: .radialBasisFunction, degree: 0, gamma: 0.5, coef0: 0.0))
svm.train(trainData)

Throws Index out of range error in SVM.swift in two places:
Line 1531 and Line 1197

Can the input a discrete value?

I haven't tested yet but i would like to ask if the input can be discrete value like 'Hot' 'Cold' 'Windy' instead of 1 2 3 or can say continuous value?

Thanks a lot for your help

SVM Training error is: invalidModelType Error

i ran the code which is svm.trainClassifier(...) however they always say that there is an error so i use the catch and print out what type of error is

do {
//            try svm.train(trainData)
    try svm.trainClassifier(trainData)
        }
        catch let error as Error {
            print("SVM Training error is: \(error)")
        }

that and the result is 'invalidModelType' even though i set the type is

let svm = SVMModel(problemType: .c_SVM_Classification, kernelSettings: KernelParameters(type: .linear, degree: 0, gamma: 0.5, coef0: 0.0))

according to the instruction.

Thanks for your help

Abort with payload

New issue dear Kevin,

Last week, i put the lib in successfully, But now it imported fine, but whenever i install the project by Xcode it always stuck here and said that abort with payload, which i dont get the reason why. At first i thought some of my project aren't working right. So i deleted and commented code and some thing like that. But everything still got this issue. Until i delete this subproject out of my project the code runs fine.

Here is the error, i dont know what is this, and dont even now this is error or not.

screen shot 2017-02-02 at 12 37 26 pm

screen shot 2017-02-02 at 12 37 38 pm

Thanks for your help

RNN>feedForward>SoftMax "sum" in wrong place?

SoftMax output gives me all +inf's as results...

Looking at the source (Recur...swift), it looks like the "sum" calculation is happening for activation function sigmoidWithCrossEntropy instead of softMax?

Otherwise, "sum" just gets tossed away, while softMax is always dividing by 0.

Line 808+:

//  Run through the non-linearity
        var sum = 0.0
        for node in 0..<numNodes {
            switch (activation) {
            case .none:
                h[node] = z[node]
                break
            case .hyperbolicTangent:
                h[node] = tanh(z[node])
                break
            case .sigmoidWithCrossEntropy:
                h[node] = 1.0 / (1.0 + exp(-z[node]))
                sum += h[node] // ** <-- THIS... **
                break
            case .sigmoid:
                h[node] = 1.0 / (1.0 + exp(-z[node]))
                break
            case .rectifiedLinear:
                h[node] = z[node]
                if (z[node] < 0) { h[node] = 0.0 }
                break
            case .softSign:
                h[node] = z[node] / (1.0 + abs(z[node]))
                break
            case .softMax:
                h[node] = exp(z[node])
                sum += h[node] // ** <-- ..SHOULD BE HERE? **
                break
            }
        }

        if (activation == .softMax) {
            var scale = 1.0 / sum       //  Do division once for efficiency  ** ~~BOOM~~ **
        .
        .
        .

SVM regressor predictOne()

While implementing your fabulous SVM class (as a regressor), I always fall upon an error while running predictOne().
The error happens here :
"var sum = 0.0
for k in 0..<supportVectorCount[0] {
sum += coefficients[0][coeffStart[0]+k] * kernelValue[coeffStart[0]+k]
}
for k in 0..<supportVectorCount[1] {
sum += coefficients[0][coeffStart[1]+k] * kernelValue[coeffStart[1]+k]
}"
the vectorSupport exist, the totalSupportVector is >0. Yet the supportVectorCount is nil.
Is it because I am in the regressor mode and not the classification mode ? I did not look at the classification cases yet.
So, basically, the two "for in" instructions cited above will always fail.

I came around this by creating a mock function like this :
open func predictOneJY (_ inputs: [Double]) -> Double {
var sum = 0.0
for i in 0..<totalSupportVectors {
let kernelValue = Kernel.calcKernelValue(kernelParams, x: inputs, y: supportVector[i])
sum += coefficients[0][i] * kernelValue
}
sum -= ฯ[0]
return sum
}
It returns the correct ouput AFAIK.
But I wonder if there is something that I miss, and it is, in fact, my implementation that is faulty, or if the code of predictOne() could indeed be "streamlined" or "corrected" for the regressor cases.
And thanks again for your magnificent and very useful project.

PCA

i) Your library is great.
ii) In the function "getReducedBasisVectorSet(_ data: MLDataSet)",
at the end when you create the basisVectors matrice, should it not be
basisVectors[(vector * initialDimension) + column] = vTranspose[vector + (column * initialDimension)]
instead of
basisVectors[(vector * reducedDimension) + column] = vTranspose[vector + (column * initialDimension)]
?

Can not import into Swift Project

I have done exactly what the manual showed. But still. When i tried to import AIToolbox into Xcode project (my iphone application project) i couldn't do it?

That would be nice to get your help. Thanks.
screen shot 2017-01-24 at 12 16 15 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.