Beispiel #1
0
    def calculate_bandwidth_correl(sample_):
        import kern_density_est
        optimum = {}

        if likelihood_cross_validation:
            if domain:
                print "negative_interactions"
                optimum[
                    "positive_interactions"] = kern_density_est.chrom_cross_validation_correlation(
                        prior_elements,
                        data_set_name,
                        thresholds=np.linspace(0.01, .4, 200),
                        classification_of_interactions="positive_interactions")
                optimum[
                    "negative_interactions"] = kern_density_est.chrom_cross_validation_correlation(
                        prior_elements,
                        data_set_name,
                        thresholds=np.linspace(0.01, .4, 200),
                        classification_of_interactions="negative_interactions")
            else:
                optimum[
                    "positive_interactions"] = kern_density_est.chrom_cross_validation_correlation(
                        prior_elements,
                        data_set_name,
                        thresholds=np.linspace(0.01, .4, 200),
                        classification_of_interactions="positive_interactions")
                optimum["negative_interactions"] = "scott"
        else:

            optimum[
                "positive_interactions"] = kern_density_est.cross_validation(
                    sample_["positive_interactions"])
            optimum["negative_interactions"] = "scott"

        return optimum
Beispiel #2
0
    def calculate_bandwidth_dist(sample_):
        import kern_density_est
        optimum = {}
        if domain: print "positive_interactions"

        if likelihood_cross_validation:
            if domain:
                print "negative_interactions"
                optimum[
                    "positive_interactions"] = kern_density_est.chrom_cross_validation_distance(
                        prior_elements,
                        thresholds=np.linspace(0.01, .4, 200),
                        classification_of_interactions="positive_interactions",
                        weights=weights)
                optimum[
                    "negative_interactions"] = kern_density_est.chrom_cross_validation_distance(
                        prior_elements,
                        thresholds=np.linspace(0.01, .4, 200),
                        classification_of_interactions="negative_interactions",
                        weights=weights)
            else:
                optimum[
                    "positive_interactions"] = kern_density_est.chrom_cross_validation_distance(
                        prior_elements,
                        thresholds=np.linspace(0.01, .4, 200),
                        classification_of_interactions="positive_interactions")
                optimum["negative_interactions"] = {}
                for positive_or_negative_side in [
                        "positive_side", "negative_side"
                ]:
                    optimum["negative_interactions"][
                        positive_or_negative_side] = "scott"

        else:
            optimum["positive_interactions"] = {}
            optimum["negative_interactions"] = {}
            for positive_or_negative_side in [
                    "positive_side", "negative_side"
            ]:
                optimum["positive_interactions"][
                    positive_or_negative_side] = kern_density_est.cross_validation(
                        sample_[positive_or_negative_side]
                        ["positive_interactions"])
                optimum["negative_interactions"][
                    positive_or_negative_side] = "scott"

        return optimum
	def calculate_bandwidth_correl(sample_):
		import kern_density_est
		optimum = {}
		
		if likelihood_cross_validation:
			if domain:
				print "negative_interactions"
				optimum["positive_interactions"] = kern_density_est.chrom_cross_validation_correlation(prior_elements, data_set_name, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "positive_interactions")
				optimum["negative_interactions"] = kern_density_est.chrom_cross_validation_correlation(prior_elements, data_set_name, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "negative_interactions")
			else: 
				optimum["positive_interactions"] = kern_density_est.chrom_cross_validation_correlation(prior_elements, data_set_name, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "positive_interactions")
				optimum["negative_interactions"] = "scott"
		else: 
				
			optimum["positive_interactions"] = kern_density_est.cross_validation(sample_["positive_interactions"])
			optimum["negative_interactions"] = "scott"

		return optimum
	def calculate_bandwidth_dist(sample_):
		import kern_density_est
		optimum = {}
		if domain: print "positive_interactions"

		if likelihood_cross_validation:
			if domain:
				print "negative_interactions"
				optimum["positive_interactions"] = kern_density_est.chrom_cross_validation_distance(prior_elements, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "positive_interactions", weights = weights)
				optimum["negative_interactions"] = kern_density_est.chrom_cross_validation_distance(prior_elements, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "negative_interactions", weights = weights)
			else: 
				optimum["positive_interactions"] = kern_density_est.chrom_cross_validation_distance(prior_elements, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "positive_interactions")
				optimum["negative_interactions"] = {}
				for positive_or_negative_side in ["positive_side", "negative_side"]: 
					optimum["negative_interactions"][positive_or_negative_side] = "scott"

		else: 
			optimum["positive_interactions"] = {}
			optimum["negative_interactions"] = {}
			for positive_or_negative_side in ["positive_side", "negative_side"]: 
				optimum["positive_interactions"][positive_or_negative_side] = kern_density_est.cross_validation(sample_[positive_or_negative_side]["positive_interactions"])
				optimum["negative_interactions"][positive_or_negative_side] = "scott"

		return optimum
	def calculate_or_plot_kern(attribute_of_interaction_, sample_, l_limit, up_limit, number_of_bins, colour = ("r", "b"), weights_ = None, bandwidth_pos = None, bandwidth_neg = None):
	
		prob_ = {}
		bins_ = {}
		import kern_density_est
		kern_density_est.plot_atr = plot_atr_kernel

		xgrid = [[],[]]
		xgrid[0] = np.linspace(l_limit, up_limit, number_of_bins[0])
		xgrid[1] = np.linspace(l_limit, up_limit, number_of_bins[1])

		if domain:
	
			if attribute_of_interaction_ == "distance":


				#prob_["positive_interactions"], bins_["positive_interactions"] = kern_density_est.kern_scipy_gaus_weighted(sample_["positive_interactions"], colour[0], xgrid[0], weights = weights_["positive_interactions"], bandwidth = "scott", factor = None)#bandwidth_pos)
				#prob_["negative_interactions"], bins_["negative_interactions"] = kern_density_est.kern_scipy_gaus_weighted(sample_["negative_interactions"], colour[1], xgrid[1], weights = weights_["negative_interactions"], bandwidth = "scott", factor = None)#bandwidth_neg)
				prob_["positive_interactions"], bins_["positive_interactions"] = kern_density_est.kern_scipy_gaus_weighted(sample_["positive_interactions"], colour[0], xgrid[0], weights = weights_["positive_interactions"], bandwidth = bandwidth_pos, plot_atr = True)#bandwidth_pos)
				prob_["negative_interactions"], bins_["negative_interactions"] = kern_density_est.kern_scipy_gaus_weighted(sample_["negative_interactions"], colour[1], xgrid[1], weights = weights_["negative_interactions"], bandwidth = bandwidth_neg, plot_atr = True)#bandwidth_neg)

				#bandwidth_pos = kern_density_est.cross_validation(sample_["positive_interactions"])# * sample_["positive_interactions"].std(ddof=1)
				#bandwidth_neg = kern_density_est.cross_validation(sample_["negative_interactions"])# * sample_["negative_interactions"].std(ddof=1)

				#prob_["positive_interactions"], bins_["positive_interactions"] = kern_density_est.kernel_weighted_samples(sample_["positive_interactions"], colour[0], xgrid[0], weights = weights_["positive_interactions"], fft = False, bw=bandwidth_pos)
				#prob_["negative_interactions"], bins_["negative_interactions"] = kern_density_est.kernel_weighted_samples(sample_["negative_interactions"], colour[1], xgrid[1], weights = weights_["negative_interactions"], fft = False, bw=bandwidth_neg)

			else:
				#kernel_ = "gaussian"

				#bandwidth_pos = kern_density_est.cross_validation(sample_["positive_interactions"], kernel = kernel_) # kernel = 
				#bandwidth_neg = kern_density_est.cross_validation(sample_["negative_interactions"], kernel = kernel_)

				#prob_["positive_interactions"], bins_["positive_interactions"] = kern_density_est.kern_sklearn_expon(sample_["positive_interactions"], colour[0], xgrid[0], bandwidth = bandwidth_pos, kernel_ = kernel_)
				#prob_["negative_interactions"], bins_["negative_interactions"] = kern_density_est.kern_sklearn_expon(sample_["negative_interactions"], colour[1], xgrid[1], bandwidth = bandwidth_neg, kernel_ = kernel_)

				bandwidth_pos = kern_density_est.chrom_cross_validation_correlation(prior_elements, data_set_name, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "positive_interactions", plot_likelihood_function = False)
				bandwidth_neg = kern_density_est.chrom_cross_validation_correlation(prior_elements, data_set_name, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "negative_interactions", plot_likelihood_function = False)

				prob_["positive_interactions"], bins_["positive_interactions"] = kern_density_est.kern_scipy_gaus(sample_["positive_interactions"], colour[0], xgrid[0], bandwidth = bandwidth_pos)
				prob_["negative_interactions"], bins_["negative_interactions"] = kern_density_est.kern_scipy_gaus(sample_["negative_interactions"], colour[1], xgrid[1], bandwidth = bandwidth_neg)	
		else:
			#if attribute_of_interaction_ == "distance": bandwidth_pos = optimum["distance"][ite]
			#else: bandwidth_pos = optimum[data_set_name]

				
			if attribute_of_interaction_ == "distance" and positive_or_negative_side == "negative_side": label_1, label_2 = None, None
			else: label_1, label_2 = "positive interactions", "negative interactions"

			if likelihood_cross_validation:
				if attribute_of_interaction_ == "correlation":
					bandwidth_pos = kern_density_est.chrom_cross_validation_correlation(prior_elements, data_set_name, thresholds = np.linspace(0.01, .4, 200), classification_of_interactions = "positive_interactions", plot_likelihood_function = False)

				print bandwidth_pos
				prob_["positive_interactions"], bins_["positive_interactions"] = kern_density_est.kern_scipy_gaus(sample_["positive_interactions"], colour[0], xgrid[0], bandwidth = bandwidth_pos, label = label_1)
				prob_["negative_interactions"], bins_["negative_interactions"] = kern_density_est.kern_scipy_gaus(sample_["negative_interactions"], colour[1], xgrid[1], bandwidth = "scott", label = label_2)	
			else:

				bandwidth_pos = kern_density_est.cross_validation(sample_["positive_interactions"])# * sample_["positive_interactions"].std(ddof=1)
				print bandwidth_pos
				prob_["positive_interactions"], bins_["positive_interactions"] = kern_density_est.kern_scipy_gaus(sample_["positive_interactions"], colour[0], xgrid[0], bandwidth=bandwidth_pos, label = label_1)
				prob_["negative_interactions"], bins_["negative_interactions"] = kern_density_est.kern_scipy_gaus(sample_["negative_interactions"], colour[1], xgrid[1], bandwidth="scott", label = label_2)
				


		if use_smooth_prior_for_estimation:	return  prob_, bins_
		else: return  [[], []], [[], []]