diff --git a/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/DimensionalityReductionAlgorithm.java b/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/DimensionalityReductionAlgorithm.java index 7b3ebd053..a38a0ff3e 100644 --- a/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/DimensionalityReductionAlgorithm.java +++ b/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/DimensionalityReductionAlgorithm.java @@ -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 @@ -31,7 +31,8 @@ public enum DimensionalityReductionAlgorithm { UMAP( "UMAP", "Uniform Manifold Approximation and Projection for Dimension Reduction." ), - TSNE( "t-SNE", "t-distributed Stochastic Neighbor Embedding." ); + TSNE( "t-SNE", "t-distributed Stochastic Neighbor Embedding." ), + PCA( "PCA", "Principal Component Analysis." ),; private final String name; diff --git a/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/DimensionalityReductionController.java b/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/DimensionalityReductionController.java index d08ca2fab..a784d3a5b 100644 --- a/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/DimensionalityReductionController.java +++ b/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/DimensionalityReductionController.java @@ -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 @@ -37,13 +37,16 @@ import org.mastodon.graph.Edge; import org.mastodon.graph.ReadOnlyGraph; import org.mastodon.graph.Vertex; +import org.mastodon.mamut.feature.branch.dimensionalityreduction.pca.BranchPcaFeatureComputer; import org.mastodon.mamut.feature.branch.dimensionalityreduction.tsne.BranchTSneFeatureComputer; import org.mastodon.mamut.feature.branch.dimensionalityreduction.umap.BranchUmapFeatureComputer; +import org.mastodon.mamut.feature.dimensionalityreduction.pca.AbstractPcaFeatureComputer; import org.mastodon.mamut.feature.dimensionalityreduction.tsne.TSneSettings; import org.mastodon.mamut.feature.dimensionalityreduction.tsne.feature.AbstractTSneFeatureComputer; import org.mastodon.mamut.feature.dimensionalityreduction.umap.UmapSettings; import org.mastodon.mamut.feature.dimensionalityreduction.umap.feature.AbstractUmapFeatureComputer; import org.mastodon.mamut.feature.dimensionalityreduction.util.InputDimension; +import org.mastodon.mamut.feature.spot.dimensionalityreduction.pca.SpotPcaFeatureComputer; import org.mastodon.mamut.feature.spot.dimensionalityreduction.tsne.SpotTSneFeatureComputer; import org.mastodon.mamut.feature.spot.dimensionalityreduction.umap.SpotUmapFeatureComputer; import org.mastodon.mamut.model.Link; @@ -210,6 +213,12 @@ public void setAlgorithm( final DimensionalityReductionAlgorithm algorithm ) throw new ArrayIndexOutOfBoundsException( "Not enough data for t-SNE computation." ); } break; + case PCA: + AbstractPcaFeatureComputer< V, E, G > pcaFeatureComputer = + isModelGraph ? Cast.unchecked( new SpotPcaFeatureComputer( model, context ) ) + : Cast.unchecked( new BranchPcaFeatureComputer( model, context ) ); + pcaFeatureComputer.computeFeature( commonSettings, inputDimensions, graph ); + break; default: throw new IllegalArgumentException( "Unknown algorithm: " + algorithm ); } diff --git a/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/ui/DimensionalityReductionView.java b/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/ui/DimensionalityReductionView.java index 9ad578064..676d59e7e 100644 --- a/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/ui/DimensionalityReductionView.java +++ b/src/main/java/org/mastodon/mamut/feature/dimensionalityreduction/ui/DimensionalityReductionView.java @@ -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 @@ -89,6 +89,8 @@ public class DimensionalityReductionView extends JFrame private final JRadioButton tsneRadioButton; + private final JRadioButton pcaRadioButton; + private final JCheckBox standardizeFeaturesCheckBox; private final JSpinner numberOfDimensionsInput; @@ -133,6 +135,7 @@ public DimensionalityReductionView( final Model model, final Context context ) umapRadioButton = new JRadioButton( "UMAP" ); tsneRadioButton = new JRadioButton( "t-SNE" ); + pcaRadioButton = new JRadioButton( "PCA" ); // Common settings standardizeFeaturesCheckBox = new JCheckBox( "Standardize features" ); @@ -166,6 +169,7 @@ private void initSettings() DimensionalityReductionAlgorithm algorithm = controller.getAlgorithm(); umapRadioButton.setSelected( algorithm == DimensionalityReductionAlgorithm.UMAP ); tsneRadioButton.setSelected( algorithm == DimensionalityReductionAlgorithm.TSNE ); + pcaRadioButton.setSelected( algorithm == DimensionalityReductionAlgorithm.PCA ); CommonSettings settings = controller.getCommonSettings(); UmapSettings umapSettings = controller.getUmapSettings(); TSneSettings tSneSettings = controller.getTSneSettings(); @@ -192,10 +196,12 @@ private void initBehavior() umapRadioButton.addActionListener( e -> updateAlgorithmSettings() ); tsneRadioButton.addActionListener( e -> updateAlgorithmSettings() ); + pcaRadioButton.addActionListener( e -> updateAlgorithmSettings() ); ButtonGroup algorithmGroup = new ButtonGroup(); algorithmGroup.add( umapRadioButton ); algorithmGroup.add( tsneRadioButton ); + algorithmGroup.add( pcaRadioButton ); CommonSettings commonSettings = controller.getCommonSettings(); UmapSettings umapSettings = controller.getUmapSettings(); @@ -224,12 +230,13 @@ private void initLayout() { add( canvas, BorderLayout.CENTER ); - canvas.add( new JLabel( "Graph type:" ), "split 3" ); + canvas.add( new JLabel( "Graph type:" ), "split 4" ); canvas.add( modelGraphRadioButton ); canvas.add( branchGraphRadioButton, "wrap" ); - canvas.add( new JLabel( "Algorithm:" ), "split 3" ); + canvas.add( new JLabel( "Algorithm:" ), "split 4" ); canvas.add( umapRadioButton ); - canvas.add( tsneRadioButton, "wrap" ); + canvas.add( tsneRadioButton ); + canvas.add( pcaRadioButton, "wrap" ); canvas.add( standardizeFeaturesCheckBox, "wrap" ); canvas.add( new JLabel( "Number of dimensions:" ), SPLIT_2 ); canvas.add( numberOfDimensionsInput, WMIN_35_WRAP ); @@ -280,8 +287,10 @@ private void updateAlgorithmSettings() DimensionalityReductionAlgorithm algorithm; if ( umapRadioButton.isSelected() ) algorithm = DimensionalityReductionAlgorithm.UMAP; - else + else if ( tsneRadioButton.isSelected() ) algorithm = DimensionalityReductionAlgorithm.TSNE; + else + algorithm = DimensionalityReductionAlgorithm.PCA; controller.setAlgorithm( algorithm ); addAlgorithmSpecificSettings( algorithm ); revalidate(); @@ -305,6 +314,10 @@ private void addAlgorithmSpecificSettings( final DimensionalityReductionAlgorith algorithmSpecificSettingsPanel.add( new JLabel( "Maximum number of iterations:" ), SPLIT_2 ); algorithmSpecificSettingsPanel.add( maxIterationsInput, WMIN_35_WRAP ); break; + case PCA: + algorithmSpecificSettingsPanel.add( new JLabel( "" ), "wrap" ); + algorithmSpecificSettingsPanel.add( new JLabel( "" ), "wrap" ); + break; default: break; }