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
| /** Cosine similarity **/ | |
| private func cosineSim(A: [Double], B: [Double]) -> Double { | |
| return dot(A: A, B: B) / (magnitude(A: A) * magnitude(A: B)) | |
| } | |
| /** Dot Product **/ | |
| private func dot(A: [Double], B: [Double]) -> Double { | |
| var x: Double = 0 | |
| for i in 0...A.count-1 { | |
| x += A[i] * B[i] |
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 os | |
| import pickle | |
| import warnings | |
| import numpy as np | |
| import pandas as pd | |
| from sklearn.model_selection import train_test_split | |
| from tensorflow.keras.callbacks import EarlyStopping | |
| from tensorflow.keras.layers import Dense | |
| from tensorflow.keras.layers import Dropout |
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
| -(float)compareString:(NSString *)originalString withString:(NSString *)comparisonString | |
| { | |
| // Normalize strings | |
| [originalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
| [comparisonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
| originalString = [originalString lowercaseString]; | |
| comparisonString = [comparisonString lowercaseString]; | |
| // Step 1 (Steps follow description at http://www.merriampark.com/ld.htm) |