@@ -0,0 +1,3285 @@
+/*%0A * SwapParameterOperator.java%0A *%0A * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard%0A *%0A * This file is part of BEAST.%0A * See the NOTICE file distributed with this work for additional%0A * information regarding copyright ownership and licensing.%0A *%0A * BEAST is free software; you can redistribute it and/or modify%0A * it under the terms of the GNU Lesser General Public License as%0A * published by the Free Software Foundation; either version 2%0A * of the License, or (at your option) any later version.%0A *%0A *  BEAST is distributed in the hope that it will be useful,%0A *  but WITHOUT ANY WARRANTY; without even the implied warranty of%0A *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A *  GNU Lesser General Public License for more details.%0A *%0A * You should have received a copy of the GNU Lesser General Public%0A * License along with BEAST; if not, write to the%0A * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,%0A * Boston, MA  02110-1301  USA%0A */%0A%0Apackage dr.inference.operators;%0A%0Aimport dr.inference.model.Parameter;%0Aimport dr.inferencexml.operators.SwapOperatorParser;%0Aimport dr.math.MathUtils;%0A%0Aimport java.util.List;%0A%0A/**%0A * A generic operator swapping all values (dimensions) between two or more parameters%0A *%0A * @author Marc A. Suchard%0A */%0Apublic class SwapParameterOperator extends SimpleMCMCOperator %7B%0A%0A    public SwapParameterOperator(List%3CParameter%3E parameterList, double weight) %7B%0A        this.parameterList = parameterList;%0A%0A        if (parameterList.size() %3C 2) %7B%0A            throw new IllegalArgumentException(%22More than 1 parameter is needed%22);%0A        %7D%0A%0A        int size = parameterList.get(0).getDimension();%0A        for (int i = 1; i %3C parameterList.size(); ++i) %7B%0A            if (size != parameterList.get(i).getDimension()) %7B%0A                throw new IllegalArgumentException(%22All parameters most be the same size%22);%0A            %7D%0A        %7D%0A%0A        setWeight(weight);%0A    %7D%0A%0A%0A    /**%0A     * swap all values in two random parameters.%0A     */%0A    public final double doOperation() %7B%0A%0A        int i = MathUtils.nextInt(parameterList.size());%0A        int j = i;%0A%0A        while (j == i) %7B%0A            j = MathUtils.nextInt(parameterList.size());%0A        %7D%0A%0A        Parameter a = parameterList.get(i);%0A        Parameter b = parameterList.get(j);%0A%0A        for (int k = 0; k %3C a.getDimension(); ++k) %7B%0A            double tmp = a.getParameterValue(k);%0A            a.setParameterValueQuietly(k, b.getParameterValue(k));%0A            b.setParameterValueQuietly(k, tmp);%0A        %7D%0A%0A        a.fireParameterChangedEvent();%0A        b.fireParameterChangedEvent();%0A%0A        return 0.0;%0A    %7D%0A%0A    private String getParameterNames() %7B%0A        if (parameterNames == null) %7B%0A            StringBuilder sb = new StringBuilder();%0A            for (Parameter p : parameterList) %7B%0A                sb.append(p.getParameterName()).append(%22.%22);%0A            %7D%0A        %7D%0A        return parameterNames;%0A    %7D%0A%0A    public String getOperatorName() %7B%0A        return SwapOperatorParser.SWAP_OPERATOR + %22(%22 + getParameterNames() + %22swap)%22;%0A    %7D%0A%0A    public String getPerformanceSuggestion() %7B%0A        return %22No suggestions%22;%0A    %7D%0A%0A    //PRIVATE STUFF%0A%0A    private final List%3CParameter%3E parameterList;%0A    private String parameterNames = null;%0A%7D%0A

Swap all parameter values for tipDate swaps