CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-flink--flink-ml-uber-2-11

Comprehensive machine learning library for Apache Flink that enables scalable ML pipelines on distributed stream processing platform.

Pending
Overview
Eval results
Files

parameter-system.mddocs/

Parameter System

Type-safe parameter management system with validation, default values, and JSON serialization support. Essential for configuring ML algorithms and components with runtime safety and persistence capabilities.

Capabilities

Params Class

Core parameter container that provides type-safe parameter storage with JSON serialization.

/**
 * Map-like container for parameters with type safety and serialization
 * Supports validation, default values, and JSON persistence
 */
public class Params implements Serializable, Cloneable {
    
    /** Get number of parameters stored */
    public int size();
    
    /** Remove all parameters */
    public void clear();
    
    /** Check if container is empty */
    public boolean isEmpty();
    
    /** Get parameter value with default handling */
    public <V> V get(ParamInfo<V> info);
    
    /** Set parameter value with type safety */
    public <V> Params set(ParamInfo<V> info, V value);
    
    /** Remove specific parameter */
    public <V> void remove(ParamInfo<V> info);
    
    /** Check if parameter exists */
    public <V> boolean contains(ParamInfo<V> info);
    
    /** Serialize all parameters to JSON */
    public String toJson();
    
    /** Load parameters from JSON string */
    public void loadJson(String json);
    
    /** Merge with another Params instance */
    public Params merge(Params otherParams);
    
    /** Create deep copy of parameters */
    public Params clone();
}

Usage Examples:

import org.apache.flink.ml.api.misc.param.Params;
import org.apache.flink.ml.api.misc.param.ParamInfo;

// Create parameter definitions
ParamInfo<Integer> MAX_ITER = ParamInfoFactory
    .createParamInfo("maxIter", Integer.class)
    .setDescription("Maximum number of iterations")
    .setHasDefaultValue(100)
    .build();

ParamInfo<Double> LEARNING_RATE = ParamInfoFactory
    .createParamInfo("learningRate", Double.class)
    .setDescription("Learning rate for optimization")
    .setRequired()
    .build();

// Create and populate parameters
Params params = new Params();
params.set(MAX_ITER, 200);
params.set(LEARNING_RATE, 0.01);

// Check parameter existence and get values
if (params.contains(LEARNING_RATE)) {
    double lr = params.get(LEARNING_RATE);
    System.out.println("Learning rate: " + lr);
}

// Get value with default fallback
int maxIter = params.get(MAX_ITER); // Returns 200, or 100 if not set

// Serialize and deserialize
String json = params.toJson();
Params loaded = new Params();
loaded.loadJson(json);

// Merge parameters
Params otherParams = new Params().set(MAX_ITER, 300);
Params merged = params.merge(otherParams);

ParamInfo Class

Parameter metadata and definition class that provides type information, validation, and default values.

/**
 * Parameter definition with metadata, validation, and default values
 * @param <V> The parameter value type
 */
public class ParamInfo<V> {
    
    /** Get parameter name identifier */
    public String getName();
    
    /** Get parameter aliases for backward compatibility */
    public String[] getAlias();
    
    /** Get human-readable parameter description */
    public String getDescription();
    
    /** Check if parameter is optional */
    public boolean isOptional();
    
    /** Check if parameter has a default value */
    public boolean hasDefaultValue();
    
    /** Get default value if available */
    public V getDefaultValue();
    
    /** Get parameter validator */
    public ParamValidator<V> getValidator();
    
    /** Get parameter value class */
    public Class<V> getValueClass();
}

ParamInfoFactory Class

Factory for creating ParamInfo instances with builder pattern support.

/**
 * Factory for creating ParamInfo instances with fluent builder pattern
 */
public class ParamInfoFactory {
    
    /** Create builder for parameter definition */
    public static <V> ParamInfoBuilder<V> createParamInfo(String name, Class<V> valueClass);
}

ParamInfoBuilder Class

Builder for constructing ParamInfo instances with validation and metadata.

/**
 * Builder for constructing ParamInfo instances
 * @param <V> The parameter value type
 */
public static class ParamInfoBuilder<V> {
    
    /** Set parameter aliases for backward compatibility */
    public ParamInfoBuilder<V> setAlias(String[] alias);
    
    /** Set human-readable description */
    public ParamInfoBuilder<V> setDescription(String description);
    
    /** Mark parameter as optional */
    public ParamInfoBuilder<V> setOptional();
    
    /** Mark parameter as required */
    public ParamInfoBuilder<V> setRequired();
    
    /** Set default value for parameter */
    public ParamInfoBuilder<V> setHasDefaultValue(V defaultValue);
    
    /** Set validation function */
    public ParamInfoBuilder<V> setValidator(ParamValidator<V> validator);
    
    /** Build final ParamInfo instance */
    public ParamInfo<V> build();
}

Usage Example:

// Create comprehensive parameter definition
ParamInfo<String> ALGORITHM = ParamInfoFactory
    .createParamInfo("algorithm", String.class)
    .setDescription("Algorithm type for classification")
    .setAlias(new String[]{"algo", "method"})
    .setHasDefaultValue("logistic")
    .setValidator(value -> 
        Arrays.asList("logistic", "svm", "tree").contains(value))
    .build();

// Create required parameter with validation
ParamInfo<Integer> NUM_FEATURES = ParamInfoFactory
    .createParamInfo("numFeatures", Integer.class)
    .setDescription("Number of input features")
    .setRequired()
    .setValidator(value -> value > 0)
    .build();

ParamValidator Interface

Interface for implementing parameter value validation.

/**
 * Interface for parameter value validation
 * @param <V> The parameter value type to validate
 */
public interface ParamValidator<V> extends Serializable {
    
    /** Validate parameter value, return true if valid */
    boolean validate(V value);
}

Usage Examples:

// Range validator
ParamValidator<Double> rangeValidator = value -> value >= 0.0 && value <= 1.0;

// Enum validator  
ParamValidator<String> enumValidator = value -> 
    Arrays.asList("auto", "manual", "hybrid").contains(value);

// Custom complex validator
ParamValidator<Integer[]> arrayValidator = value -> {
    if (value == null || value.length == 0) return false;
    return Arrays.stream(value).allMatch(v -> v > 0);
};

WithParams Interface

Common interface for classes that use the parameter system.

/**
 * Common interface for parameter handling
 * @param <T> The implementing class type for method chaining
 */
public interface WithParams<T> {
    
    /** Get all parameters */
    Params getParams();
    
    /** Set parameter value with type safety and method chaining */
    <V> T set(ParamInfo<V> info, V value);
    
    /** Get parameter value with default handling */
    <V> V get(ParamInfo<V> info);
}

Implementation Example:

public class MyEstimator implements WithParams<MyEstimator> {
    private Params params = new Params();
    
    // Parameter definitions
    public static final ParamInfo<Integer> MAX_ITER = ParamInfoFactory
        .createParamInfo("maxIter", Integer.class)
        .setHasDefaultValue(100)
        .build();
    
    public static final ParamInfo<Double> TOLERANCE = ParamInfoFactory
        .createParamInfo("tolerance", Double.class)
        .setHasDefaultValue(1e-6)
        .build();
    
    @Override
    public Params getParams() {
        return params;
    }
    
    @Override
    public <V> MyEstimator set(ParamInfo<V> info, V value) {
        params.set(info, value);
        return this;
    }
    
    @Override
    public <V> V get(ParamInfo<V> info) {
        return params.get(info);
    }
    
    // Convenience methods
    public MyEstimator setMaxIter(int maxIter) {
        return set(MAX_ITER, maxIter);
    }
    
    public int getMaxIter() {
        return get(MAX_ITER);
    }
    
    public MyEstimator setTolerance(double tolerance) {
        return set(TOLERANCE, tolerance);
    }
    
    public double getTolerance() {
        return get(TOLERANCE);
    }
}

ExtractParamInfosUtil Utility

Utility for extracting parameter information from WithParams classes.

/**
 * Utility for extracting ParamInfo instances from WithParams classes
 */
public class ExtractParamInfosUtil {
    
    /** Extract all ParamInfo instances from a WithParams object */
    public static List<ParamInfo> extractParamInfos(WithParams s);
}

Usage Example:

MyEstimator estimator = new MyEstimator();
List<ParamInfo> paramInfos = ExtractParamInfosUtil.extractParamInfos(estimator);

// Inspect available parameters
for (ParamInfo info : paramInfos) {
    System.out.println("Parameter: " + info.getName());
    System.out.println("Description: " + info.getDescription());
    System.out.println("Optional: " + info.isOptional());
    System.out.println("Default: " + info.getDefaultValue());
    System.out.println();
}

Parameter System Benefits

The parameter system provides several key advantages:

  1. Type Safety: Compile-time type checking prevents parameter type errors
  2. Validation: Runtime validation ensures parameter values are valid
  3. Default Values: Automatic fallback to sensible defaults
  4. Serialization: JSON persistence for saving/loading configurations
  5. Documentation: Built-in parameter descriptions and metadata
  6. Method Chaining: Fluent API for configuration
  7. Backward Compatibility: Alias support for parameter name changes

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-flink--flink-ml-uber-2-11

docs

algorithm-operators.md

environment-management.md

index.md

linear-algebra.md

parameter-system.md

pipeline-base-classes.md

pipeline-framework.md

utility-libraries.md

tile.json