This file contains 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
public static void main(String[] args) { | |
int[] sizes = new int[] { 5000, 10000, 50000, 100000, | |
1000000, 5000000, 10000000 }; | |
for (int numInstances : sizes) { | |
List<LoanApplication> data = getRandomData(numInstances); | |
List<LoanApplication> testData = extractTestData(data, 100); | |
NearestNeighborClassifier<LoanApplication> classifier; |
This file contains 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
enum Gender{ | |
Male, | |
Female | |
} | |
enum Carrier { | |
Telenor, | |
Telia | |
} |
This file contains 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
public interface DistanceFunction<T> { | |
double calculateDistance(T item, T item2); | |
} |
This file contains 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
public double calculateDistance(LoanApplication item, LoanApplication item2) { | |
double distance = 0; | |
//nominal attributes | |
if (item.getCarrier() != item2.getCarrier()) distance += 1; | |
if (item.getGender() != item2.getGender()) distance += 1; | |
int dayDiff = Math.abs(item.getDayOfWeek() - item2.getDayOfWeek()); | |
if (dayDiff > 3) { | |
dayDiff -= 1 + 2 * (dayDiff - 4); |
This file contains 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
public double classify(T item) { | |
int numItems = items.size(); | |
// calculated distances in same order as the items list | |
double[] distances = new double[numItems]; | |
//calculate the distance to each instance | |
for (int i = 0; i < numItems; i++) { | |
distances[i] = distanceFunction.calculateDistance(item, items.get(i)); |
This file contains 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
/** | |
* Thread pool from the Java 1.5 Executor Framework | |
*/ | |
private ExecutorService executorService; | |
/** | |
* Initialize the thread pool | |
*/ | |
private void init() { | |
int numThreads = Runtime.getRuntime().availableProcessors(); |
This file contains 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
/* | |
* The Sql Server Object Explorer Window of Visual Studio 2012 | |
* doesn't release connections properly. Here is a workaround | |
* | |
*/ | |
-- 1. Open a query window, either VS or SSMS will do | |
-- 2. Run the following select, replacing 'MyDB' with the name of your DB |
This file contains 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
// With Asyncronous journaling enabled, commands are queued and written | |
// to the journal by a background thread. This increases query and command throughput | |
// but there is risk of losing commands in the case of a system failure | |
var config = new EngineConfiguration(); | |
config.AsyncronousJournaling = true; | |
var engine = Engine.LoadOrCreate<MyModel>(config); | |
This file contains 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
public class FrontierEvaluator : Evaluator | |
{ | |
public override float Evaluate(Disc playerToMove, Board board) | |
{ | |
int frontierDiscComparison = Square.All | |
.Where(square => board[(Square) square] != Disc.None) | |
.Sum(square => square.Neighbors | |
.Count(neighbor => neighbor != null && board[neighbor] == Disc.None) * | |
(board[square] == playerToMove ? -1 : 1)); | |
return frontierDiscComparison; |
This file contains 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
---------LiveDomain.Core.Compression.DeflateStreamCompressor--------- | |
Compress: 1266235 | |
Decompress: 1007630 | |
Compression: 0,377149519090644 | |
---------LiveDomain.Core.Compression.GzipCompressor--------- | |
Compress: 513028 | |
Decompress: 417533 | |
Compression: 0,382395802972894 | |
---------LiveDomain.Core.Compression.LzfCompressionAdapter--------- | |
Compress: 486846 |