Make it less wrong

This commit is contained in:
Alexey Milovidov 2022-01-02 22:42:56 +03:00
parent 4a094c2efd
commit cf66716cd6
6 changed files with 25 additions and 33 deletions

View File

@ -1,7 +1,6 @@
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <AggregateFunctions/CrossTab.h>
#include <AggregateFunctions/FactoryHelpers.h>
#include <AggregateFunctions/Helpers.h>
#include <memory>
#include <cmath>
@ -12,31 +11,29 @@ namespace DB
namespace
{
struct ContingencyData : CrossTabData
{
static const char * getName()
struct ContingencyData : CrossTabData
{
return "contingency";
}
static const char * getName() { return "contingency"; }
Float64 getResult() const
{
if (count < 2)
return std::numeric_limits<Float64>::quiet_NaN();
Float64 phi = 0.0;
for (const auto & [key, value_ab] : count_ab)
Float64 getResult() const
{
Float64 value_a = count_a.at(key.items[0]);
Float64 value_b = count_b.at(key.items[1]);
if (count < 2)
return std::numeric_limits<Float64>::quiet_NaN();
phi += value_ab * value_ab / (value_a * value_b) * count - 2 * value_ab + (value_a * value_b) / count;
Float64 phi = 0.0;
for (const auto & [key, value_ab] : count_ab)
{
Float64 value_a = count_a.at(key.items[0]);
Float64 value_b = count_b.at(key.items[1]);
phi += value_ab * value_ab / (value_a * value_b) * count - 2 * value_ab + (value_a * value_b) / count;
}
phi /= count;
return sqrt(phi / (phi + count));
}
phi /= count;
return sqrt(phi / (phi + count));
}
};
};
}
void registerAggregateFunctionContingency(AggregateFunctionFactory & factory)
{
@ -49,5 +46,3 @@ void registerAggregateFunctionContingency(AggregateFunctionFactory & factory)
}
}
}

View File

@ -1,7 +1,6 @@
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <AggregateFunctions/CrossTab.h>
#include <AggregateFunctions/FactoryHelpers.h>
#include <AggregateFunctions/Helpers.h>
#include <memory>
#include <cmath>

View File

@ -1,7 +1,6 @@
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <AggregateFunctions/CrossTab.h>
#include <AggregateFunctions/FactoryHelpers.h>
#include <AggregateFunctions/Helpers.h>
#include <memory>
#include <cmath>

View File

@ -1,7 +1,6 @@
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <AggregateFunctions/CrossTab.h>
#include <AggregateFunctions/FactoryHelpers.h>
#include <AggregateFunctions/Helpers.h>
#include <memory>
#include <cmath>
@ -40,12 +39,14 @@ struct TheilsUData : CrossTabData
dep += (value_ab / count) * log(value_ab / value_b);
}
dep -= h_x;
dep /= h_x;
dep -= h_a;
dep /= h_a;
return dep;
}
};
}
void registerAggregateFunctionTheilsU(AggregateFunctionFactory & factory)
{
factory.registerFunction(TheilsUData::getName(),
@ -57,5 +58,3 @@ void registerAggregateFunctionTheilsU(AggregateFunctionFactory & factory)
}
}
}

View File

@ -113,12 +113,12 @@ public:
this->data(place).merge(this->data(rhs));
}
void serialize(ConstAggregateDataPtr __restrict place, WriteBuffer & buf) const override
void serialize(ConstAggregateDataPtr __restrict place, WriteBuffer & buf, std::optional<size_t>) const override
{
this->data(place).serialize(buf);
}
void deserialize(AggregateDataPtr __restrict place, ReadBuffer & buf, Arena *) const override
void deserialize(AggregateDataPtr __restrict place, ReadBuffer & buf, std::optional<size_t>, Arena *) const override
{
this->data(place).deserialize(buf);
}

View File

@ -263,7 +263,7 @@ public:
return it->getMapped();
}
typename Cell::Mapped & ALWAYS_INLINE at(const Key & x) const
const typename Cell::Mapped & ALWAYS_INLINE at(const Key & x) const
{
if (auto it = this->find(x); it != this->end())
return it->getMapped();