Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ctakes.ytex.kernel;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.ctakes.ytex.kernel.dao.ClassifierEvaluationDao;
import org.apache.ctakes.ytex.kernel.dao.KernelEvaluationDao;
import org.apache.ctakes.ytex.kernel.model.CrossValidationFold;
import org.apache.ctakes.ytex.kernel.model.KernelEvaluation;
import org.apache.ctakes.ytex.kernel.model.KernelEvaluationInstance;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import javax.sql.DataSource;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
public class KernelUtilImpl implements KernelUtil {
private static final Logger LOGGER = LoggerFactory.getLogger( "KernelUtilImpl" );
private ClassifierEvaluationDao classifierEvaluationDao;
private JdbcTemplate jdbcTemplate = null;
private KernelEvaluationDao kernelEvaluationDao = null;
private PlatformTransactionManager transactionManager;
private FoldGenerator foldGenerator = null;
public FoldGenerator getFoldGenerator() {
return foldGenerator;
}
public void setFoldGenerator(FoldGenerator foldGenerator) {
this.foldGenerator = foldGenerator;
}
private Map createInstanceIdToIndexMap(
SortedSet instanceIDs) {
Map instanceIdToIndexMap = new HashMap(
instanceIDs.size());
int i = 0;
for (Long instanceId : instanceIDs) {
instanceIdToIndexMap.put(instanceId, i);
i++;
}
return instanceIdToIndexMap;
}
@Override
public void fillGramMatrix(final KernelEvaluation kernelEvaluation,
final SortedSet trainInstanceLabelMap,
final double[][] trainGramMatrix) {
// final Set kernelEvaluationNames = new HashSet(1);
// kernelEvaluationNames.add(name);
// prepare map of instance id to gram matrix index
final Map trainInstanceToIndexMap = createInstanceIdToIndexMap(trainInstanceLabelMap);
// iterate through the training instances
for (Map.Entry instanceIdIndex : trainInstanceToIndexMap
.entrySet()) {
// index of this instance
final int indexThis = instanceIdIndex.getValue();
// id of this instance
final long instanceId = instanceIdIndex.getKey();
// get all kernel evaluations for this instance in a new transaction
// don't want too many objects in hibernate session
TransactionTemplate t = new TransactionTemplate(
this.transactionManager);
t.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW);
t.execute(new TransactionCallback