def learning_model_factory(weights=None): return LearningModel(pcDataset, trainingDataset, batch=batchSize, epocs=nEpocs, vf=validation_fraction, hidden=hiddenLayers, activation=activation, weights=weights)
def learning_model_factory(weights=None): return LearningModel(inputDataset, trainingDataset, layers, batch=batchSize, lrate=learnRate, stop_condition=stopCondition, loss_function=loss_function, momentum=momentum, decay=decay, nesterov=nesterov, orthoWts=orthoWts, epocs=nEpocs, vf=validation_fraction, weights=weights)
def direct_learning_model_factory_trainable(): layers3[0].setTrainable(True) return LearningModel(reanalysisInputDataset, trainingDataset, layers3, verbose=False, eager=eagerExe, batch=batchSize, earlyTermIndex=earlyTermIndex, lrate=learnRate, stop_condition=stopCondition, shuffle=shuffle, loss_function=loss_function, momentum=momentum, decay=decay, nesterov=nesterov, epocs=nEpocs, vf=validation_fraction, weights=result.final_weights)
def pc_learning_model_factory(inputs=pcInputDataset, target=trainingDataset, weights=None): return LearningModel(inputs, target, layers2, verbose=False, eager=eagerExe, batch=batchSize, earlyTermIndex=earlyTermIndex, lrate=learnRate, stop_condition=stopCondition, shuffle=shuffle, loss_function=loss_function, momentum=momentum, decay=decay, nesterov=nesterov, orthoWts=orthoWts, epocs=nEpocs, vf=validation_fraction, weights=weights)
learning_range = CTimeRange.new( "1980-1-1", "2005-12-30" ) prediction_lag = CDuration.months(1) nInterationsPerProc = 10 batchSize = 100 nEpocs = 200 validation_fraction = 0.15 hiddenLayers = [100] activation = "relu" plotPrediction = True variables = [ Variable("ts"), Variable( "zg", 50000 ) ] project = Project(outDir,projectName) pcDataset = ClimateleDataset([Experiment(project, start_year, end_year, nModes, variable) for variable in variables], nts = nTS, smooth = smooth, timeRange = learning_range) td = IITMDataSource( "AI", "monthly" ) trainingDataset = TrainingDataset.new( [td], pcDataset, prediction_lag, decycle=True ) #ref_time_range = ( "1980-1-1", "2014-12-1" ) #ref_ts = ProjectDataSource( "HadISST_1.cvdp_data.1980-2017", [ "nino34" ], ref_time_range ) def learning_model_factory( weights = None ): return LearningModel( pcDataset, trainingDataset, batch=batchSize, epocs=nEpocs, vf=validation_fraction, hidden=hiddenLayers, activation=activation, weights=weights ) result = LearningModel.parallel_execute( learning_model_factory, nInterationsPerProc ) print "Got Best result, valuation loss = " + str( result.val_loss ) + " training loss = " + str( result.train_loss ) if plotPrediction: plot_title = "Training data with Prediction ({0}->IITM-AI, lag {1}) {2}-{3} (loss: {4}, Epochs: {5})".format(pcDataset.getVariableIds(),prediction_lag,start_year,end_year,result.val_loss,result.nEpocs) learningModel = learning_model_factory() learningModel.plotPrediction( result, plot_title )
from cliMLe.trainingData import * from cliMLe.learning import FitResult, LearningModel, ActivationTarget import matplotlib.pyplot as plt strong_monsoon = ActivationTarget(3.0, "Strong Monsoon") weak_monsoon = ActivationTarget(-3.0, "Weak Monsoon") instance = "ams-2" activation_target = strong_monsoon learningModel, model, result = LearningModel.getActivationBackProjection( instance, activation_target.value) inputs = learningModel.inputs fig, ax = plt.subplots() y_pos = np.arange(result.shape[0]) plt.bar(y_pos, result, align='center', alpha=0.5) plt.ylabel('Activation') plt.title(activation_target.title + ' Activtion Plot') plt.show()
from cliMLe.trainingData import * from cliMLe.learning import FitResult, LearningModel instance = "good_1" (learningModel, result) = LearningModel.loadInstance(instance) varIds = learningModel.inputs.getVariableIds() trainingId = learningModel.outputs.id() plot_title = "Training data with Prediction ({0}->{1}) (loss: {2}, Epochs: {3})".format( varIds, trainingId, result.val_loss, result.nEpocs) learningModel.plotPrediction( result, "All-India Monsoon Rainfall Prediction, 1 Year Lag Time")
from cliMLe.learning import LearningModel from cliMLe.analytics import Visualizer instances = ["ams-zg-16-16-" + str(index) for index in range(1, 11)] target_values = [3.0, -3.0] results = {} for iT, target_value in enumerate(target_values): for iI, instance in enumerate(instances): learningModel, model, weights = LearningModel.getActivationBackProjection( instance, target_value) patterns = Visualizer.getWeightedPatterns(learningModel, weights) if iI == 0: results[iT] = patterns[0] else: results[iT] = results[iT] + patterns[0] results[2] = results[0] - results[1] Visualizer.mpl_spaceplot(results.values(), [ "500 mbar Height - Strong Monsoon", "500 mbar Height - Weak Monsoon", "Difference" ])
earlyTermIndex=earlyTermIndex, lrate=learnRate, stop_condition=stopCondition, shuffle=shuffle, loss_function=loss_function, momentum=momentum, decay=decay, nesterov=nesterov, orthoWts=orthoWts, epocs=nEpocs, vf=validation_fraction, weights=weights) learning_model_factory = direct_learning_model_factory result = LearningModel.fit(learning_model_factory, nInterationsPerProc, nShuffles, parallelExe) def direct_learning_model_factory_trainable(): layers3[0].setTrainable(True) return LearningModel(reanalysisInputDataset, trainingDataset, layers3, verbose=False, eager=eagerExe, batch=batchSize, earlyTermIndex=earlyTermIndex, lrate=learnRate, stop_condition=stopCondition, shuffle=shuffle, loss_function=loss_function,
end_year = 2015 nModes = 32 nTS = 1 smooth = 0 learning_range = CTimeRange.new( "1980-1-1", "2014-12-30" ) prediction_lag = CDuration.months(6) nInterations = 10 batchSize = 100 nEpocs = 200 validation_fraction = 0.15 hiddenLayers = [100] activation = "relu" plotPrediction = True variables = [ Variable("ts") ] # , Variable( "zg", 50000 ) ] project = Project(outDir,projectName) pcDataset = ClimateleDataset([Experiment(project, start_year, end_year, nModes, variable) for variable in variables], nts = nTS, smooth = smooth, timeRange = learning_range) td = ProjectDataSource( "HadISST_1.cvdp_data.1980-2017", [ "nino34" ] ) # , "pdo_timeseries_mon", "indian_ocean_dipole", "nino34" trainingDataset = TrainingDataset.new( [td], pcDataset, prediction_lag ) def learning_model_factory(): return LearningModel( pcDataset, trainingDataset, batch=batchSize, epocs=nEpocs, vf=validation_fraction, hidden=hiddenLayers, activation=activation ) result = LearningModel.serial_execute( learning_model_factory, nInterations ) print "Got Best result, val_loss = " + str( result.val_loss ) if plotPrediction: plot_title = "Training data with Prediction ({0}->nino34, lag {1}) {2}-{3} ({4} Epochs)".format(pcDataset.getVariableIds(),prediction_lag,start_year,end_year,nEpocs) learningModel = learning_model_factory( ) learningModel.plotPrediction( result, plot_title )