Skip to content

Commit

Permalink
Make Random data generation with seed reproducible independent of ord…
Browse files Browse the repository at this point in the history
…er of execution of tests
  • Loading branch information
stefanhahmann committed Dec 2, 2024
1 parent 2d7ebda commit 9ccd2e9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

public class RandomDataTools
{
private static final Random random = new Random( 42 );

public static double[][] generateSampleData()
{
return generateSampleData( 50, 100 );
Expand All @@ -32,6 +30,8 @@ private static double[][] generateRandomPointsInSphere( double centerX, double c
{
double[][] points = new double[ numberOfPoints ][ 3 ];

final Random random = new Random( 42 );

for ( int i = 0; i < numberOfPoints; i++ )
{
double r = radius * Math.cbrt( random.nextDouble() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main( final String[] args )
TSneConfiguration config = setUpTSne( inputData );
BarnesHutTSne tsne = new ParallelBHTsne(); // according to https://github.com/lejon/T-SNE-Java/ the parallel version is faster at same accuracy
double[][] tsneResult = tsne.tsne( config );
PlotPoints.plot( inputData, tsneResult, resultValues -> resultValues[ 0 ] > 10 );
PlotPoints.plot( inputData, tsneResult, resultValues -> resultValues[ 0 ] > 18 );
}

static TSneConfiguration setUpTSne( double[][] inputData )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void test()
assertEquals( 2, tsneResult[ 0 ].length );

for ( int i = 0; i < numCluster1; i++ )
assertTrue( tsneResult[ i ][ 0 ] > 10 );
assertTrue( tsneResult[ i ][ 0 ] > 18 );
for ( int i = numCluster1; i < numCluster1 + numCluster2; i++ )
assertTrue( tsneResult[ i ][ 0 ] < 10 );
assertTrue( tsneResult[ i ][ 0 ] < 18 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Expand Down Expand Up @@ -48,8 +48,8 @@ void test()
assertEquals( umapResult.length, sampleData.length );
assertEquals( 2, umapResult[ 0 ].length );
for ( int i = 0; i < 50; i++ )
assertTrue( umapResult[ i ][ 0 ] < 0 );
for ( int i = 50; i < 150; i++ )
assertTrue( umapResult[ i ][ 0 ] > 0 );
for ( int i = 50; i < 150; i++ )
assertTrue( umapResult[ i ][ 0 ] < 0 );
}
}

0 comments on commit 9ccd2e9

Please sign in to comment.