Skip to content

Commit

Permalink
Pull out common parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
minnerbe committed Aug 17, 2023
1 parent 5eedaf1 commit 36663c4
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.janelia.render.client.newsolver.assembly.Assembler;
import org.janelia.render.client.newsolver.assembly.ZBlockSolver;
import org.janelia.render.client.newsolver.assembly.matches.SameTileMatchCreatorAffine2D;
import org.janelia.render.client.newsolver.assembly.matches.SameTileMatchCreatorAffineIntensity;
import org.janelia.render.client.newsolver.blockfactories.ZBlockFactory;
import org.janelia.render.client.newsolver.blocksolveparameters.FIBSEMAlignmentParameters;
import org.janelia.render.client.newsolver.setup.AffineSolverSetup;
Expand All @@ -25,11 +24,9 @@
import org.slf4j.LoggerFactory;

import mpicbg.models.Affine2D;
import mpicbg.models.AffineModel1D;
import mpicbg.models.AffineModel2D;
import mpicbg.models.Model;
import mpicbg.models.RigidModel2D;
import mpicbg.models.TranslationModel1D;

public class AffineDistributedSolver
{
Expand Down Expand Up @@ -153,24 +150,13 @@ public static void main( final String[] args ) throws IOException

LOG.info( "computed " + allItems.size() + " blocks, maxId=" + maxId);

/*
final ZBlockSolver< List< AffineModel1D >, TranslationModel1D, List< AffineModel1D > > solver1D =
new ZBlockSolver<>(
new TranslationModel1D(),
new SameTileMatchCreatorAffineIntensity(),
cmdLineSetup.maxPlateauWidthGlobal,
cmdLineSetup.maxAllowedErrorGlobal,
cmdLineSetup.maxIterationsGlobal,
cmdLineSetup.threadsGlobal );
*/

final ZBlockSolver< AffineModel2D, RigidModel2D, AffineModel2D > solver =
new ZBlockSolver<>(
new RigidModel2D(),
new SameTileMatchCreatorAffine2D<AffineModel2D>(),
cmdLineSetup.maxPlateauWidthGlobal,
cmdLineSetup.maxAllowedErrorGlobal,
cmdLineSetup.maxIterationsGlobal,
cmdLineSetup.distributedSolve.maxPlateauWidthGlobal,
cmdLineSetup.distributedSolve.maxAllowedErrorGlobal,
cmdLineSetup.distributedSolve.maxIterationsGlobal,
cmdLineSetup.threadsGlobal );

final Assembler< AffineModel2D, RigidModel2D, AffineModel2D, ZBlockFactory > assembler = new Assembler<>( allItems, solver );
Expand Down Expand Up @@ -235,8 +221,8 @@ protected ZBlockFactory setupBlockFactory()
{
final int minZ = (int)Math.round( renderSetup.minZ );
final int maxZ = (int)Math.round( renderSetup.maxZ );
final int blockSize = cmdLineSetup.blockSize;
final int minBlockSize = cmdLineSetup.minBlockSize;
final int blockSize = cmdLineSetup.distributedSolve.blockSize;
final int minBlockSize = cmdLineSetup.distributedSolve.minBlockSize;

return new ZBlockFactory( minZ, maxZ, blockSize, minBlockSize );
}
Expand All @@ -247,7 +233,7 @@ protected < M extends Model< M > & Affine2D< M >, S extends Model< S > & Affine2
{
final boolean stitchFirst = cmdLineSetup.stitchFirst;

final FIBSEMAlignmentParameters< M, S > solveParams = new FIBSEMAlignmentParameters< M, S >(
return new FIBSEMAlignmentParameters<>(
blockModel,
(Function< Integer,S > & Serializable )(z) -> stitchingModel,
stitchFirst ? (Function< Integer, Integer > & Serializable )(z) -> cmdLineSetup.minStitchingInliers : null,
Expand All @@ -269,8 +255,6 @@ protected < M extends Model< M > & Affine2D< M >, S extends Model< S > & Affine2
cmdLineSetup.stack,
cmdLineSetup.matchOwner,
cmdLineSetup.matchCollection );

return solveParams;
}

protected < M extends Model< M > & Affine2D< M >, S extends Model< S > & Affine2D< S > > BlockCollection< M, AffineModel2D, FIBSEMAlignmentParameters< M, S >, ZBlockFactory > setupBlockCollection(
Expand All @@ -284,10 +268,7 @@ protected < M extends Model< M > & Affine2D< M >, S extends Model< S > & Affine2
final FIBSEMAlignmentParameters< M, S > defaultSolveParams =
setupSolveParameters( blockModel, stitchingModel );

final BlockCollection< M, AffineModel2D, FIBSEMAlignmentParameters< M, S >, ZBlockFactory > col =
blockFactory.defineBlockCollection( rtsc -> defaultSolveParams );

return col;
return blockFactory.defineBlockCollection(rtsc -> defaultSolveParams );
}

protected < M extends Model< M > & Affine2D< M >, S extends Model< S > & Affine2D< S > > ArrayList< AffineAlignBlockWorker<M, S, ZBlockFactory > > createWorkers(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.janelia.render.client.newsolver.blocksolveparameters;

import mpicbg.models.Affine1D;
import mpicbg.models.AffineModel1D;
import mpicbg.models.AffineModel2D;
import mpicbg.models.Model;

import org.janelia.render.client.newsolver.BlockData;
Expand All @@ -11,6 +13,7 @@
import org.janelia.render.client.parameter.IntensityAdjustParameters;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -19,63 +22,59 @@
*
* @param <M> the final block solve type (the result)
*/
public class FIBSEMIntensityCorrectionParameters<M extends Model<M> & Affine1D<M>>
extends BlockDataSolveParameters<M, M, FIBSEMIntensityCorrectionParameters<M>> {
public class FIBSEMIntensityCorrectionParameters<M>
extends BlockDataSolveParameters<M, ArrayList<AffineModel1D>, FIBSEMIntensityCorrectionParameters<M>> {
private static final long serialVersionUID = -5349107301431384524L;

final private List<Double> blockOptimizerLambdasTranslation;
final private List<Double> blockOptimizerLambdasIdentity;
final private List<Integer> blockOptimizerIterations;
final private List<Integer> blockMaxPlateauWidth;

final private IntensityAdjustParameters intensityParameters;
private final String intensityCorrectedFilterStack;
private final long maxNumberOfCachedPixels;
private final double lambdaTranslation;
private final double lambdaIdentity;
private final double renderScale;
private final int numCoefficients;
private final Integer zDistance;

public FIBSEMIntensityCorrectionParameters(
final M blockSolveModel,
final List<Double> blockOptimizerLambdasTranslation,
final List<Double> blockOptimizerLambdasIdentity,
final List<Integer> blockOptimizerIterations,
final List<Integer> blockMaxPlateauWidth,
final String baseDataUrl,
final String owner,
final String project,
final IntensityAdjustParameters parameters) {
super(baseDataUrl, owner, project, parameters.stack, blockSolveModel.copy());
final String stack,
final String intensityCorrectedFilterStack,
final long maxNumberOfCachedPixels,
final double lambdaTranslation,
final double lambdaIdentity,
final double renderScale,
final int numCoefficients,
final Integer zDistance) {
// TODO: properly copy blockSolveModel
super(baseDataUrl, owner, project, stack, blockSolveModel);

this.blockOptimizerLambdasTranslation = blockOptimizerLambdasTranslation;
this.blockOptimizerLambdasIdentity = blockOptimizerLambdasIdentity;
this.blockOptimizerIterations = blockOptimizerIterations;
this.blockMaxPlateauWidth = blockMaxPlateauWidth;
this.intensityParameters = parameters;
this.intensityCorrectedFilterStack = intensityCorrectedFilterStack;
this.maxNumberOfCachedPixels = maxNumberOfCachedPixels;
this.lambdaTranslation = lambdaTranslation;
this.lambdaIdentity = lambdaIdentity;
this.renderScale = renderScale;
this.numCoefficients = numCoefficients;
this.zDistance = zDistance;
}

public List<Double> blockOptimizerLambdasTranslation() { return blockOptimizerLambdasTranslation; }
public List<Double> blockOptimizerLambdasRigid() { return blockOptimizerLambdasIdentity; }
public List<Integer> blockOptimizerIterations() { return blockOptimizerIterations; }
public List<Integer> blockMaxPlateauWidth() {return blockMaxPlateauWidth; }

public String intensityCorrectedFilterStack() { return intensityParameters.intensityCorrectedFilterStack; }
public String matchCollection() { return intensityParameters.matchCollection; }
public long maxNumberOfCachedPixels() { return intensityParameters.getMaxNumberOfCachedPixels(); }
public double lambdaTranslation() { return intensityParameters.lambda1; }
public double lambdaIdentity() { return intensityParameters.lambda2; }
public double renderScale() { return intensityParameters.renderScale; }
public int numCoefficients() { return intensityParameters.numCoefficients; }
public Integer zDistance() { return intensityParameters.zDistance; }
public String intensityCorrectedFilterStack() { return intensityCorrectedFilterStack; }
public long maxNumberOfCachedPixels() { return maxNumberOfCachedPixels; }
public double lambdaTranslation() { return lambdaTranslation; }
public double lambdaIdentity() { return lambdaIdentity; }
public double renderScale() { return renderScale; }
public int numCoefficients() { return numCoefficients; }
public Integer zDistance() { return zDistance; }

@Override
public <F extends BlockFactory<F>> Worker<M, M, FIBSEMIntensityCorrectionParameters<M>, F> createWorker(
final BlockData<M, M, FIBSEMIntensityCorrectionParameters<M>, F> blockData,
public <F extends BlockFactory<F>> Worker<M, ArrayList<AffineModel1D>, FIBSEMIntensityCorrectionParameters<M>, F> createWorker(
final BlockData<M, ArrayList<AffineModel1D>, FIBSEMIntensityCorrectionParameters<M>, F> blockData,
final int startId,
final int threadsWorker )
{
try
{
return new AffineIntensityCorrectionBlockWorker<>( blockData, startId, threadsWorker );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
final int threadsWorker) {
try {
return new AffineIntensityCorrectionBlockWorker<>(blockData, startId, threadsWorker);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public SerializableValuePair<Integer, Integer> convert( final String value )
@ParametersDelegate
public RenderWebServiceParameters renderWeb = new RenderWebServiceParameters();

@ParametersDelegate
public DistributedSolveParameters distributedSolve = new DistributedSolveParameters();

@Parameter(
names = "--stack",
description = "Stack name",
Expand Down Expand Up @@ -72,22 +75,6 @@ public SerializableValuePair<Integer, Integer> convert( final String value )
)
public String matchCollection;

//
// not required parameters
//

@Parameter(
names = "--blockSize",
description = "The size of the blocks in z, which will be computed in paralell (default:500, min:3) "
)
public Integer blockSize = 500;

@Parameter(
names = "--minBlockSize",
description = "The minimal size of the blocks in z, which will be computed in paralell (default: 50) "
)
public Integer minBlockSize = 50;

//
// stitching align model, by TRANSLATION with tunable regularization --- with RIGID (default: 0.00)
//
Expand Down Expand Up @@ -188,27 +175,6 @@ public SerializableValuePair<Integer, Integer> convert( final String value )
@Parameter(names = "--maxZRangeMatches", description = "max z-range in which to load matches (default: '-1' - no limit)")
public int maxZRangeMatches = -1;

//
// global assembly solve paramters
//
@Parameter(
names = "--maxAllowedErrorGlobal",
description = "Max allowed error global"
)
public Double maxAllowedErrorGlobal = 10.0;

@Parameter(
names = "--maxIterationsGlobal",
description = "Max iterations global"
)
public Integer maxIterationsGlobal = 10000;

@Parameter(
names = "--maxPlateauWidthGlobal",
description = "Max plateau width global"
)
public Integer maxPlateauWidthGlobal = 500;

//
// for saving and running
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.janelia.render.client.newsolver.setup;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;

import java.io.Serializable;

/**
* Parameters for distributed solver.
*
* @author Michael Innerberger
*/
@Parameters
public class DistributedSolveParameters implements Serializable {

// Initialization parameters
@Parameter(
names = "--blockSize",
description = "The size of the blocks in z, which will be computed in paralell (default:500, min:3) "
)
public Integer blockSize = 500;

@Parameter(
names = "--minBlockSize",
description = "The minimal size of the blocks in z, which will be computed in parallel (default: 50) "
)
public Integer minBlockSize = 50;

// global assembly solve parameters
@Parameter(
names = "--maxAllowedErrorGlobal",
description = "Max allowed error global"
)
public Double maxAllowedErrorGlobal = 10.0;

@Parameter(
names = "--maxIterationsGlobal",
description = "Max iterations global"
)
public Integer maxIterationsGlobal = 10000;

@Parameter(
names = "--maxPlateauWidthGlobal",
description = "Max plateau width global"
)
public Integer maxPlateauWidthGlobal = 500;

public DistributedSolveParameters() {}

public DistributedSolveParameters(
final Integer blockSize,
final Integer minBlockSize,
final Double maxAllowedErrorGlobal,
final Integer maxIterationsGlobal,
final Integer maxPlateauWidthGlobal) {

if (blockSize < 3)
throw new RuntimeException("Blocksize has to be >= 3.");
if (minBlockSize < 1)
throw new RuntimeException("MinBlockSize has to be > 0.");
if (maxAllowedErrorGlobal < 0)
throw new RuntimeException("MaxAllowedErrorGlobal has to be >= 0.");
if (maxIterationsGlobal < 1)
throw new RuntimeException("MaxIterationsGlobal has to be > 0.");
if (maxPlateauWidthGlobal < 1)
throw new RuntimeException("MaxPlateauWidthGlobal has to be > 0.");

this.blockSize = blockSize;
this.minBlockSize = minBlockSize;
this.maxAllowedErrorGlobal = maxAllowedErrorGlobal;
this.maxIterationsGlobal = maxIterationsGlobal;
this.maxPlateauWidthGlobal = maxPlateauWidthGlobal;
}
}
Loading

0 comments on commit 36663c4

Please sign in to comment.