//----------------------
void tmVisThreshC1_MixtureModeling2::setValues() {	
	mu1 = 0; 
	mu2 = 0;
	sigma2_1 = 0; 
	sigma2_2 = 0;
	max1 = 0; 
	max2 = 0;
	cardinal1 = 0; 
	cardinal2 = 0;

	for (int i=MIN_VAL_8u; i<=index ; i++) {
	    cardinal1 +=  histogram[i];
	    mu1 += i*histogram[i];
	}

	for (int i=index+1; i<=MAX_VAL_8u ; i++) {
	    cardinal2 +=  histogram[i];
	    mu2 += i*histogram[i];
	}

	if(cardinal1 == 0) {
	    mu1 = 0;
	    sigma2_1 = 0;
	} else {
   		mu1 /= (float)cardinal1; 
   	}

	if(cardinal2 == 0) {
	    mu2 = 0;
	    sigma2_2 = 0;
	} else {
    	mu2 /= (float)cardinal2; 
    }

	if( mu1 != 0 ) {
	    for(int i=MIN_VAL_8u; i<=index ; i++) {
			sigma2_1 += histogram[i]*pow(i-mu1,2);
		}
	    sigma2_1 /= (float)cardinal1;

	    max1 = calculateMax((int) mu1);
	    mult1 = (float) max1;
	    twoVariance1 = 2*sigma2_1; 
	}
	
	if( mu2 != 0 ) {
	    for(int i=index+1; i<=MAX_VAL_8u ; i++) {
			sigma2_2 += histogram[i]*pow(i-mu2,2);
		}
	    sigma2_2 /= (float)cardinal2;

	    max2 = calculateMax((int) mu2);
	    mult2 = (float) max2;
	    twoVariance2 = 2*sigma2_2; 
	}
}
Ejemplo n.º 2
0
void GapCalculator::LaserScanGapCal(const sensor_msgs::LaserScan laser)
{
	minVDistance = 0;
	angle = laser.angle_max;

	for (unsigned int i = laser.ranges.size() - 1;
			i > (laser.ranges.size()) / 2; i--)
	{

		HDistance = laser.ranges[i] * cos(laser.angle_max - angle);

		currentSearchState = startState(currentSearchState);
		currentSearchState = calculateBase(currentSearchState, laser, i);
		currentSearchState = calculateMax(currentSearchState, laser, i);
		currentSearchState = calculateMin(currentSearchState, laser, i);

		angle -= laser.angle_increment;

	}

}
Ejemplo n.º 3
0
void AsynchronousMetrics::update()
{
    {
        if (auto mark_cache = context.getMarkCache())
        {
            set("MarkCacheBytes", mark_cache->weight());
            set("MarkCacheFiles", mark_cache->count());
        }
    }

    {
        if (auto uncompressed_cache = context.getUncompressedCache())
        {
            set("UncompressedCacheBytes", uncompressed_cache->weight());
            set("UncompressedCacheCells", uncompressed_cache->count());
        }
    }

    {
        auto databases = context.getDatabases();

        size_t max_queue_size = 0;
        size_t max_inserts_in_queue = 0;
        size_t max_merges_in_queue = 0;

        size_t sum_queue_size = 0;
        size_t sum_inserts_in_queue = 0;
        size_t sum_merges_in_queue = 0;

        size_t max_absolute_delay = 0;
        size_t max_relative_delay = 0;

        size_t max_part_count_for_partition = 0;

        for (const auto & db : databases)
        {
            for (auto iterator = db.second->getIterator(); iterator->isValid(); iterator->next())
            {
                auto & table = iterator->table();
                StorageMergeTree * table_merge_tree = typeid_cast<StorageMergeTree *>(table.get());
                StorageReplicatedMergeTree * table_replicated_merge_tree = typeid_cast<StorageReplicatedMergeTree *>(table.get());

                if (table_replicated_merge_tree)
                {
                    StorageReplicatedMergeTree::Status status;
                    table_replicated_merge_tree->getStatus(status, false);

                    calculateMaxAndSum(max_queue_size, sum_queue_size, status.queue.queue_size);
                    calculateMaxAndSum(max_inserts_in_queue, sum_inserts_in_queue, status.queue.inserts_in_queue);
                    calculateMaxAndSum(max_merges_in_queue, sum_merges_in_queue, status.queue.merges_in_queue);

                    try
                    {
                        time_t absolute_delay = 0;
                        time_t relative_delay = 0;
                        table_replicated_merge_tree->getReplicaDelays(absolute_delay, relative_delay);

                        calculateMax(max_absolute_delay, absolute_delay);
                        calculateMax(max_relative_delay, relative_delay);
                    }
                    catch (...)
                    {
                        tryLogCurrentException(__PRETTY_FUNCTION__,
                            "Cannot get replica delay for table: " + backQuoteIfNeed(db.first) + "." + backQuoteIfNeed(iterator->name()));
                    }

                    calculateMax(max_part_count_for_partition, table_replicated_merge_tree->getData().getMaxPartsCountForMonth());
                }

                if (table_merge_tree)
                {
                    calculateMax(max_part_count_for_partition, table_merge_tree->getData().getMaxPartsCountForMonth());
                }
            }
        }

        set("ReplicasMaxQueueSize", max_queue_size);
        set("ReplicasMaxInsertsInQueue", max_inserts_in_queue);
        set("ReplicasMaxMergesInQueue", max_merges_in_queue);

        set("ReplicasSumQueueSize", sum_queue_size);
        set("ReplicasSumInsertsInQueue", sum_inserts_in_queue);
        set("ReplicasSumMergesInQueue", sum_merges_in_queue);

        set("ReplicasMaxAbsoluteDelay", max_absolute_delay);
        set("ReplicasMaxRelativeDelay", max_relative_delay);

        set("MaxPartCountForPartition", max_part_count_for_partition);
    }

#if USE_TCMALLOC
    {
        /// tcmalloc related metrics. Remove if you switch to different allocator.

        MallocExtension & malloc_extension = *MallocExtension::instance();

        auto malloc_metrics =
        {
            "generic.current_allocated_bytes",
            "generic.heap_size",
            "tcmalloc.current_total_thread_cache_bytes",
            "tcmalloc.central_cache_free_bytes",
            "tcmalloc.transfer_cache_free_bytes",
            "tcmalloc.thread_cache_free_bytes",
            "tcmalloc.pageheap_free_bytes",
            "tcmalloc.pageheap_unmapped_bytes",
        };

        for (auto malloc_metric : malloc_metrics)
        {
            size_t value = 0;
            if (malloc_extension.GetNumericProperty(malloc_metric, &value))
                set(malloc_metric, value);
        }
    }
#endif

    /// Add more metrics as you wish.
}