All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ignite.ml.nn.UpdatesStrategy Maven / Gradle / Ivy

Go to download

Apache Ignite® is a Distributed Database For High-Performance Computing With In-Memory Speed.

There is a newer version: 2.15.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.ignite.ml.nn;

import java.io.Serializable;
import java.util.List;
import org.apache.ignite.ml.math.functions.IgniteFunction;
import org.apache.ignite.ml.optimization.updatecalculators.ParameterUpdateCalculator;

/**
 * Class encapsulating update strategies for group trainers based on updates.
 *
 * @param  Type of model to be optimized.
 * @param  Type of update.
 */
public class UpdatesStrategy {
    /**
     * {@link ParameterUpdateCalculator}.
     */
    private ParameterUpdateCalculator updatesCalculator;

    /**
     * Function used to reduce updates in one training (for example, sum all sequential gradient updates to get one
     * gradient update).
     */
    private IgniteFunction, U> locStepUpdatesReducer;

    /**
     * Function used to reduce updates from different trainings (for example, averaging of gradients of all parallel trainings).
     */
    private IgniteFunction, U> allUpdatesReducer;

    /**
     * Construct instance of this class with given parameters.
     *
     * @param updatesCalculator Parameter update calculator.
     * @param locStepUpdatesReducer Function used to reduce updates in one training
     * (for example, sum all sequential gradient updates to get one gradient update).
     * @param allUpdatesReducer Function used to reduce updates from different trainings
     * (for example, averaging of gradients of all parallel trainings).
     */
    public UpdatesStrategy(
        ParameterUpdateCalculator updatesCalculator,
        IgniteFunction, U> locStepUpdatesReducer,
        IgniteFunction, U> allUpdatesReducer) {
        this.updatesCalculator = updatesCalculator;
        this.locStepUpdatesReducer = locStepUpdatesReducer;
        this.allUpdatesReducer = allUpdatesReducer;
    }

    /**
     * Get parameter update calculator (see {@link ParameterUpdateCalculator}).
     *
     * @return Parameter update calculator.
     */
    public ParameterUpdateCalculator getUpdatesCalculator() {
        return updatesCalculator;
    }

    /**
     * Get function used to reduce updates in one training
     * (for example, sum all sequential gradient updates to get one gradient update).
     *
     * @return Function used to reduce updates in one training
     * (for example, sum all sequential gradient updates to get on gradient update).
     */
    public IgniteFunction, U> locStepUpdatesReducer() {
        return locStepUpdatesReducer;
    }

    /**
     * Get function used to reduce updates from different trainings
     * (for example, averaging of gradients of all parallel trainings).
     *
     * @return Function used to reduce updates from different trainings.
     */
    public IgniteFunction, U> allUpdatesReducer() {
        return allUpdatesReducer;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy