2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (c) 2021 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.examples.adaptive.concepts;
24 import java.io.Serializable;
25 import java.util.ArrayList;
26 import java.util.List;
27 import lombok.EqualsAndHashCode;
28 import lombok.ToString;
31 * The Class AutoLearn is used as a Java context for Adaptive auto-learning of trends towards a fixed value in the
36 public class AutoLearn implements Serializable {
37 private static final long serialVersionUID = 3825970380434170754L;
39 private transient List<Double> avDiffs = null;
41 private transient List<Long> counts = null;
44 * Checks if the Autolearn instance is initialized.
46 * @return true, if the Autolearn instance is initialized
48 public boolean isInitialized() {
49 return (avDiffs != null && counts != null);
53 * initializes the auto learning algorithm with the number of convergent variables to use.
55 * @param size the number of convergent variables to use
57 public void init(final int size) {
58 if (avDiffs == null || avDiffs.isEmpty()) {
59 avDiffs = new ArrayList<>(size);
60 for (var i = 0; i < size; i++) {
61 avDiffs.add(i, Double.NaN);
65 if (counts == null || counts.isEmpty()) {
66 counts = new ArrayList<>(size);
67 for (var i = 0; i < size; i++) {
74 * Gets the average difference values of the algorithm.
76 * @return the average difference values of the algorithm
78 public List<Double> getAvDiffs() {
83 * Sets the average difference values of the algorithm.
85 * @param avDiffs the average difference values of the algorithm
87 public void setAvDiffs(final List<Double> avDiffs) {
88 this.avDiffs = avDiffs;
92 * Check if the average difference values of the algorithm are set.
94 * @return true, if check set av diffs
96 public boolean checkSetAvDiffs() {
97 return ((avDiffs != null) && (!avDiffs.isEmpty()));
101 * Unset the average difference values of the algorithm.
103 public void unsetAvDiffs() {
108 * Gets the count values of the algorithm.
110 * @return the count values of the algorithm
112 public List<Long> getCounts() {
117 * Sets the count values of the algorithm.
119 * @param counts the count values of the algorithm
121 public void setCounts(final List<Long> counts) {
122 this.counts = counts;
126 * Check if the count values of the algorithm are set.
128 * @return true, if the count values of the algorithm are set
130 public boolean checkSetCounts() {
131 return ((counts != null) && (!counts.isEmpty()));
135 * Unset the count values of the algorithm.
137 public void unsetCounts() {