-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add t-SNE computation for spot and branch features
- Loading branch information
1 parent
1b0101a
commit 0375d7c
Showing
9 changed files
with
657 additions
and
4 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...ava/org/mastodon/mamut/feature/branch/dimensionalityreduction/tsne/BranchTSneFeature.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*- | ||
* #%L | ||
* mastodon-deep-lineage | ||
* %% | ||
* Copyright (C) 2022 - 2024 Stefan Hahmann | ||
* %% | ||
* 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 | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
package org.mastodon.mamut.feature.branch.dimensionalityreduction.tsne; | ||
|
||
import java.util.List; | ||
|
||
import org.mastodon.feature.Feature; | ||
import org.mastodon.feature.FeatureProjectionKey; | ||
import org.mastodon.feature.FeatureProjectionSpec; | ||
import org.mastodon.feature.FeatureSpec; | ||
import org.mastodon.feature.Multiplicity; | ||
import org.mastodon.mamut.feature.dimensionalityreduction.tsne.feature.AbstractTSneFeature; | ||
import org.mastodon.mamut.model.branch.BranchSpot; | ||
import org.mastodon.properties.DoublePropertyMap; | ||
import org.scijava.plugin.Plugin; | ||
|
||
/** | ||
* Represents a t-SNE feature for BranchSpots in the Mastodon project. | ||
* <br> | ||
* This feature is used to store the t-SNE outputs for BranchSpots. | ||
* <br> | ||
* The t-SNE outputs are stored in a list of {@link DoublePropertyMap}s. The size of the list is equal to the number of dimensions of the t-SNE output. | ||
*/ | ||
public class BranchTSneFeature extends AbstractTSneFeature< BranchSpot > | ||
{ | ||
public static final String KEY = "Branch t-SNE outputs"; | ||
|
||
private final BranchSpotTSneFeatureSpec adaptedSpec; | ||
|
||
public static final BranchSpotTSneFeatureSpec GENERIC_SPEC = new BranchSpotTSneFeatureSpec(); | ||
|
||
public BranchTSneFeature( final List< DoublePropertyMap< BranchSpot > > outputMaps ) | ||
{ | ||
super( outputMaps ); | ||
FeatureProjectionSpec[] projectionSpecs = | ||
projectionMap.keySet().stream().map( FeatureProjectionKey::getSpec ).toArray( FeatureProjectionSpec[]::new ); | ||
this.adaptedSpec = new BranchSpotTSneFeatureSpec( projectionSpecs ); | ||
} | ||
|
||
@Plugin( type = FeatureSpec.class ) | ||
public static class BranchSpotTSneFeatureSpec extends FeatureSpec< BranchTSneFeature, BranchSpot > | ||
{ | ||
public BranchSpotTSneFeatureSpec() | ||
{ | ||
super( KEY, HELP_STRING, BranchTSneFeature.class, BranchSpot.class, Multiplicity.SINGLE ); | ||
} | ||
|
||
public BranchSpotTSneFeatureSpec( final FeatureProjectionSpec... projectionSpecs ) | ||
{ | ||
super( KEY, HELP_STRING, BranchTSneFeature.class, BranchSpot.class, Multiplicity.SINGLE, projectionSpecs ); | ||
} | ||
} | ||
|
||
@Override | ||
public FeatureSpec< ? extends Feature< BranchSpot >, BranchSpot > getSpec() | ||
{ | ||
return adaptedSpec; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...mastodon/mamut/feature/branch/dimensionalityreduction/tsne/BranchTSneFeatureComputer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*- | ||
* #%L | ||
* mastodon-deep-lineage | ||
* %% | ||
* Copyright (C) 2022 - 2024 Stefan Hahmann | ||
* %% | ||
* 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 | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
package org.mastodon.mamut.feature.branch.dimensionalityreduction.tsne; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
import org.mastodon.RefPool; | ||
import org.mastodon.mamut.feature.dimensionalityreduction.tsne.feature.AbstractTSneFeature; | ||
import org.mastodon.mamut.feature.dimensionalityreduction.tsne.feature.AbstractTSneFeatureComputer; | ||
import org.mastodon.mamut.model.Model; | ||
import org.mastodon.mamut.model.branch.BranchLink; | ||
import org.mastodon.mamut.model.branch.BranchSpot; | ||
import org.mastodon.mamut.model.branch.ModelBranchGraph; | ||
import org.mastodon.properties.DoublePropertyMap; | ||
import org.scijava.Context; | ||
|
||
public class BranchTSneFeatureComputer extends AbstractTSneFeatureComputer< BranchSpot, BranchLink, ModelBranchGraph > | ||
{ | ||
|
||
public BranchTSneFeatureComputer( final Model model, final Context context ) | ||
{ | ||
super( model, context ); | ||
} | ||
|
||
@Override | ||
protected AbstractTSneFeature< BranchSpot > createFeatureInstance( final List< DoublePropertyMap< BranchSpot > > umapOutputMaps ) | ||
{ | ||
return new BranchTSneFeature( umapOutputMaps ); | ||
} | ||
|
||
@Override | ||
protected RefPool< BranchSpot > getRefPool() | ||
{ | ||
return model.getBranchGraph().vertices().getRefPool(); | ||
} | ||
|
||
@Override | ||
protected ReentrantReadWriteLock getLock( final ModelBranchGraph branchGraph ) | ||
{ | ||
return branchGraph.getLock(); | ||
} | ||
|
||
@Override | ||
protected Collection< BranchSpot > getVertices() | ||
{ | ||
return model.getBranchGraph().vertices(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...stodon/mamut/feature/branch/dimensionalityreduction/tsne/BranchTSneFeatureSerializer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*- | ||
* #%L | ||
* mastodon-deep-lineage | ||
* %% | ||
* Copyright (C) 2022 - 2024 Stefan Hahmann | ||
* %% | ||
* 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 | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
package org.mastodon.mamut.feature.branch.dimensionalityreduction.tsne; | ||
|
||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
|
||
import org.mastodon.feature.FeatureSpec; | ||
import org.mastodon.feature.io.FeatureSerializer; | ||
import org.mastodon.io.FileIdToObjectMap; | ||
import org.mastodon.io.ObjectToFileIdMap; | ||
import org.mastodon.mamut.feature.branch.BranchFeatureSerializer; | ||
import org.mastodon.mamut.feature.branch.dimensionalityreduction.BranchOutputSerializerTools; | ||
import org.mastodon.mamut.model.ModelGraph; | ||
import org.mastodon.mamut.model.Spot; | ||
import org.mastodon.mamut.model.branch.BranchSpot; | ||
import org.mastodon.mamut.model.branch.ModelBranchGraph; | ||
import org.scijava.plugin.Plugin; | ||
|
||
/** | ||
* De-/serializes {@link BranchTSneFeature} | ||
*/ | ||
@Plugin( type = FeatureSerializer.class ) | ||
public class BranchTSneFeatureSerializer implements BranchFeatureSerializer< BranchTSneFeature, BranchSpot, Spot > | ||
{ | ||
@Override | ||
public FeatureSpec< BranchTSneFeature, BranchSpot > getFeatureSpec() | ||
{ | ||
return BranchTSneFeature.GENERIC_SPEC; | ||
} | ||
|
||
@Override | ||
public void serialize( final BranchTSneFeature feature, final ObjectToFileIdMap< Spot > idmap, final ObjectOutputStream oos, | ||
final ModelBranchGraph branchGraph, final ModelGraph graph ) throws IOException | ||
{ | ||
BranchOutputSerializerTools.serialize( feature, idmap, oos, branchGraph, graph ); | ||
} | ||
|
||
@Override | ||
public BranchTSneFeature deserialize( final FileIdToObjectMap< Spot > idmap, final ObjectInputStream ois, | ||
final ModelBranchGraph branchGraph, final ModelGraph graph ) throws ClassNotFoundException, IOException | ||
{ | ||
return BranchOutputSerializerTools.deserialize( idmap, ois, branchGraph, graph, BranchTSneFeature::new ); | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
.../org/mastodon/mamut/feature/dimensionalityreduction/tsne/feature/AbstractTSneFeature.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*- | ||
* #%L | ||
* mastodon-deep-lineage | ||
* %% | ||
* Copyright (C) 2022 - 2024 Stefan Hahmann | ||
* %% | ||
* 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 | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* #L% | ||
*/ | ||
package org.mastodon.mamut.feature.dimensionalityreduction.tsne.feature; | ||
|
||
import java.util.List; | ||
|
||
import org.mastodon.graph.Vertex; | ||
import org.mastodon.mamut.feature.dimensionalityreduction.AbstractOutputFeature; | ||
import org.mastodon.properties.DoublePropertyMap; | ||
|
||
/** | ||
* This generic feature is used to store the t-SNE outputs. | ||
* <br> | ||
* The t-SNE outputs are stored in a list of {@link DoublePropertyMap}s. The size of the list is equal to the number of dimensions of the t-SNE output. | ||
*/ | ||
public abstract class AbstractTSneFeature< V extends Vertex< ? > > extends AbstractOutputFeature< V > | ||
{ | ||
private static final String PROJECTION_NAME_TEMPLATE = "tSNE%d"; | ||
|
||
protected static final String HELP_STRING = | ||
"Computes the t-SNE according to the selected input dimensions, number of target dimensions, the perplexity value and maximum number of iterations."; | ||
|
||
protected AbstractTSneFeature( final List< DoublePropertyMap< V > > umapOutputMaps ) | ||
{ | ||
super( umapOutputMaps ); | ||
} | ||
|
||
@Override | ||
protected String getProjectionNameTemplate() | ||
{ | ||
return PROJECTION_NAME_TEMPLATE; | ||
} | ||
} |
Oops, something went wrong.