Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 package org.apache.spark.ml.param;
0019 
0020 import java.util.Arrays;
0021 import java.util.List;
0022 
0023 import org.apache.spark.ml.util.Identifiable$;
0024 
0025 /**
0026  * A subclass of Params for testing.
0027  */
0028 public class JavaTestParams extends JavaParams {
0029 
0030   public JavaTestParams() {
0031     this.uid_ = Identifiable$.MODULE$.randomUID("javaTestParams");
0032     init();
0033   }
0034 
0035   public JavaTestParams(String uid) {
0036     this.uid_ = uid;
0037     init();
0038   }
0039 
0040   private String uid_;
0041 
0042   @Override
0043   public String uid() {
0044     return uid_;
0045   }
0046 
0047   private IntParam myIntParam_;
0048 
0049   public IntParam myIntParam() {
0050     return myIntParam_;
0051   }
0052 
0053   public int getMyIntParam() {
0054     return (Integer) getOrDefault(myIntParam_);
0055   }
0056 
0057   public JavaTestParams setMyIntParam(int value) {
0058     set(myIntParam_, value);
0059     return this;
0060   }
0061 
0062   private DoubleParam myDoubleParam_;
0063 
0064   public DoubleParam myDoubleParam() {
0065     return myDoubleParam_;
0066   }
0067 
0068   public double getMyDoubleParam() {
0069     return (Double) getOrDefault(myDoubleParam_);
0070   }
0071 
0072   public JavaTestParams setMyDoubleParam(double value) {
0073     set(myDoubleParam_, value);
0074     return this;
0075   }
0076 
0077   private Param<String> myStringParam_;
0078 
0079   public Param<String> myStringParam() {
0080     return myStringParam_;
0081   }
0082 
0083   public String getMyStringParam() {
0084     return getOrDefault(myStringParam_);
0085   }
0086 
0087   public JavaTestParams setMyStringParam(String value) {
0088     set(myStringParam_, value);
0089     return this;
0090   }
0091 
0092   private DoubleArrayParam myDoubleArrayParam_;
0093 
0094   public DoubleArrayParam myDoubleArrayParam() {
0095     return myDoubleArrayParam_;
0096   }
0097 
0098   public double[] getMyDoubleArrayParam() {
0099     return getOrDefault(myDoubleArrayParam_);
0100   }
0101 
0102   public JavaTestParams setMyDoubleArrayParam(double[] value) {
0103     set(myDoubleArrayParam_, value);
0104     return this;
0105   }
0106 
0107   private void init() {
0108     myIntParam_ = new IntParam(this, "myIntParam", "this is an int param", ParamValidators.gt(0));
0109     myDoubleParam_ = new DoubleParam(this, "myDoubleParam", "this is a double param",
0110       ParamValidators.inRange(0.0, 1.0));
0111     List<String> validStrings = Arrays.asList("a", "b");
0112     myStringParam_ = new Param<>(this, "myStringParam", "this is a string param",
0113       ParamValidators.inArray(validStrings));
0114     myDoubleArrayParam_ =
0115       new DoubleArrayParam(this, "myDoubleArrayParam", "this is a double param");
0116 
0117     setDefault(myIntParam(), 1);
0118     setDefault(myDoubleParam(), 0.5);
0119     setDefault(myDoubleArrayParam(), new double[]{1.0, 2.0});
0120   }
0121 
0122   @Override
0123   public JavaTestParams copy(ParamMap extra) {
0124     return defaultCopy(extra);
0125   }
0126 }