001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.math3.optimization; 019 020import org.apache.commons.math3.linear.RealMatrix; 021import org.apache.commons.math3.linear.DiagonalMatrix; 022import org.apache.commons.math3.linear.NonSquareMatrixException; 023 024/** 025 * Weight matrix of the residuals between model and observations. 026 * <br/> 027 * Immutable class. 028 * 029 * @deprecated As of 3.1 (to be removed in 4.0). 030 * @since 3.1 031 */ 032@Deprecated 033public class Weight implements OptimizationData { 034 /** Weight matrix. */ 035 private final RealMatrix weightMatrix; 036 037 /** 038 * Creates a diagonal weight matrix. 039 * 040 * @param weight List of the values of the diagonal. 041 */ 042 public Weight(double[] weight) { 043 weightMatrix = new DiagonalMatrix(weight); 044 } 045 046 /** 047 * @param weight Weight matrix. 048 * @throws NonSquareMatrixException if the argument is not 049 * a square matrix. 050 */ 051 public Weight(RealMatrix weight) { 052 if (weight.getColumnDimension() != weight.getRowDimension()) { 053 throw new NonSquareMatrixException(weight.getColumnDimension(), 054 weight.getRowDimension()); 055 } 056 057 weightMatrix = weight.copy(); 058 } 059 060 /** 061 * Gets the initial guess. 062 * 063 * @return the initial guess. 064 */ 065 public RealMatrix getWeight() { 066 return weightMatrix.copy(); 067 } 068}