1 /* 2 * This file is part of ELKI: 3 * Environment for Developing KDD-Applications Supported by Index-Structures 4 * 5 * Copyright (C) 2018 6 * ELKI Development Team 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.mktrees.mkapp; 22 23 import de.lmu.ifi.dbs.elki.database.relation.Relation; 24 import de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.AbstractMTreeFactory; 25 import de.lmu.ifi.dbs.elki.persistent.PageFile; 26 import de.lmu.ifi.dbs.elki.persistent.PageFileFactory; 27 import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil; 28 import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID; 29 import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.CommonConstraints; 30 import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization; 31 import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Flag; 32 import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.IntParameter; 33 34 /** 35 * Factory for a MkApp-Tree 36 * 37 * @author Erich Schubert 38 * @since 0.4.0 39 * 40 * @stereotype factory 41 * @navassoc - create - MkAppTreeIndex 42 * 43 * @param <O> Object type 44 */ 45 public class MkAppTreeFactory<O> extends AbstractMTreeFactory<O, MkAppTreeNode<O>, MkAppEntry, MkAppTreeSettings<O>> { 46 /** 47 * Constructor. 48 * 49 * @param pageFileFactory Data storage 50 * @param settings Tree settings 51 */ MkAppTreeFactory(PageFileFactory<?> pageFileFactory, MkAppTreeSettings<O> settings)52 public MkAppTreeFactory(PageFileFactory<?> pageFileFactory, MkAppTreeSettings<O> settings) { 53 super(pageFileFactory, settings); 54 } 55 56 @Override instantiate(Relation<O> relation)57 public MkAppTreeIndex<O> instantiate(Relation<O> relation) { 58 PageFile<MkAppTreeNode<O>> pagefile = makePageFile(getNodeClass()); 59 return new MkAppTreeIndex<>(relation, pagefile, settings); 60 } 61 getNodeClass()62 protected Class<MkAppTreeNode<O>> getNodeClass() { 63 return ClassGenericsUtil.uglyCastIntoSubclass(MkAppTreeNode.class); 64 } 65 66 /** 67 * Parameterization class. 68 * 69 * @author Erich Schubert 70 * 71 * @hidden 72 * 73 * @param <O> Object type 74 */ 75 public static class Parameterizer<O> extends AbstractMTreeFactory.Parameterizer<O, MkAppTreeNode<O>, MkAppEntry, MkAppTreeSettings<O>> { 76 /** 77 * Parameter for nolog 78 */ 79 public static final OptionID NOLOG_ID = new OptionID("mkapp.nolog", "Flag to indicate that the approximation is done in the ''normal'' space instead of the log-log space (which is default)."); 80 81 /** 82 * Parameter for k 83 */ 84 public static final OptionID K_ID = new OptionID("mkapp.k", "positive integer specifying the maximum number k of reverse k nearest neighbors to be supported."); 85 86 /** 87 * Parameter for p 88 */ 89 public static final OptionID P_ID = new OptionID("mkapp.p", "positive integer specifying the order of the polynomial approximation."); 90 91 @Override makeOptions(Parameterization config)92 protected void makeOptions(Parameterization config) { 93 super.makeOptions(config); 94 IntParameter kP = new IntParameter(K_ID) // 95 .addConstraint(CommonConstraints.GREATER_EQUAL_ONE_INT); 96 if(config.grab(kP)) { 97 settings.kmax = kP.getValue(); 98 } 99 100 IntParameter pP = new IntParameter(P_ID) // 101 .addConstraint(CommonConstraints.GREATER_EQUAL_ONE_INT); 102 if(config.grab(pP)) { 103 settings.p = pP.getValue(); 104 } 105 106 Flag nologF = new Flag(NOLOG_ID); 107 if(config.grab(nologF)) { 108 settings.log = !nologF.getValue(); 109 } 110 } 111 112 @Override makeInstance()113 protected MkAppTreeFactory<O> makeInstance() { 114 return new MkAppTreeFactory<>(pageFileFactory, settings); 115 } 116 117 @Override makeSettings()118 protected MkAppTreeSettings<O> makeSettings() { 119 return new MkAppTreeSettings<>(); 120 } 121 } 122 } 123