## machine learning – A simple clusterness measure of data in one dimension using Java – follow-up 2

(See the previous version here.)

This time, I have encorporated all the suggestions made by Marc. Also, I changed the type of points from `double` to `Number`. My newest version follows:

`com.github.coderodde.codereview.notepad.ClusternessMeasure`

``````package com.github.coderodde.codereview.notepad;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

/**
* This class implements a method for computing clusterness measure (CM). CM
* asks for a set of points {@code x_1, x_2, ..., x_n}, and it returns a
* number within {@code (0, 1)}. The idea behind CM is that it returns 0 when
* all the data points are equal and 1 whenever all adjacent points are
* equidistant.
*
* @author Rodion "rodde" Efremov
* @version 1.618 (Jun 11, 2019)
* @since 1.6 (Feb 21, 2019)
*/
public final class ClusternessMeasure {

/**
* Computes the clusterness measure of the input points.
* @param points the points to process.
* @return the number within range {@code (0, 1)}, describing how clustered
* the input points are.
*/
public static double computeClusternessMeasure(Collection<Number> points) {
return computeClusternessMeasure(
new SortedMeasurementPoints(
Objects.requireNonNull(points, "points is null")));
}

private static double computeClusternessMeasure(
SortedMeasurementPoints points) {

if (points.isEmpty()) {
throw new IllegalArgumentException("points is empty");
}

double minimumPoint = points.get(0).doubleValue();
double maximumPoint =
points.get(points.indexOfLastEntry()).doubleValue();

double range = maximumPoint - minimumPoint;

if (range == 0.0) {
// Once here, all data points are equal and so CM must be 1.0.
return 1.0;
}

double expectedDifference = range / points.indexOfLastEntry();
double sum = 0.0;

for (int i = 0; i < points.indexOfLastEntry(); i++) {
double currentDifference =
points.get(i + 1).doubleValue() -
points.get(i).doubleValue();

sum += Math.min(
Math.abs(expectedDifference - currentDifference),
expectedDifference);
}

return sum / range;
}

private static final class SortedMeasurementPoints
implements Iterable<Number> {

private final List<Number> points;

public SortedMeasurementPoints(Collection<Number> points) {
List<Number> processedPoints = new ArrayList<>(points.size());

for (Number point : points) {
if (point == null) {
NullPointerException cause =
new NullPointerException("null points detected");

throw new IllegalArgumentException(cause);
}

}

processedPoints.sort(
(a, b) -> Double.compare(
a.doubleValue(),
b.doubleValue()));

this.points = processedPoints;
}

public Number get(int index) {
return points.get(index);
}

public int indexOfLastEntry() {
return points.size() - 1;
}

public boolean isEmpty() {
return points.isEmpty();
}

// For the sake of debugging:
public Iterator<Number> iterator() {
return points.iterator();
}
}
}
``````

`com.github.coderodde.codereview.notepad.ClusternessMeasureTest`

``````package com.github.coderodde.codereview.notepad;

import java.util.Arrays;
import static junit.framework.Assert.assertEquals;
import org.junit.Test;

/**
* This unit test class tests the
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Jun 11, 2021)
* @since 1.6 (Jun 11, 2021)
*/
public class ClusternessMeasureTest {

private static final double DELTA = 1e-6;

@Test(expected = NullPointerException.class)
public void throwsOnNullPoints() {
computeClusternessMeasure(null);
}

@Test(expected = IllegalArgumentException.class)
public void throwsOnEmptyPoints() {
computeClusternessMeasure(Arrays.asList());
}

@Test(expected = IllegalArgumentException.class)
public void throwsOnNullPoint() {
computeClusternessMeasure(Arrays.asList(1.0, null, 3.0f));
}

@Test
public void computationOnSinglePoint() {
double measure = computeClusternessMeasure(Arrays.asList(1));
double expected = 1.0;
assertEquals(expected, measure, DELTA);
}

@Test
public void computationOnTwoPoints() {
double measure = computeClusternessMeasure(Arrays.asList(5, 3));
double expected = 0;
assertEquals(expected, measure, DELTA);
}

@Test
public void computeOnThreeEquidistantPoints() {
double measure = computeClusternessMeasure(Arrays.asList(3, 1, 5));
double expected = 0.0;
assertEquals(expected, measure, DELTA);
}

@Test
public void computeOnEqualPoints() {
double measure = computeClusternessMeasure(
Arrays.asList(4, 4f, 4.0, 4));

double expected = 1.0;
assertEquals(expected, measure, DELTA);
}

@Test
public void computeOnSkewedDataPoints() {
double measure = computeClusternessMeasure(Arrays.asList(1, 2.8, 3));
double expected = 0.7999999999999;
assertEquals(expected, measure, DELTA);
}
}
``````

Critique request

## pathfinder 1e – (Occult Adventures) Does Esoteric Knight’s Step Through Reality have the same drawback as Dimension Door?

From Esoteric Knight

Step through Reality (Sp)

By expending a 3rd-level spell slot as a swift action, the esoteric
knight can teleport to a space within 30 feet as if using dimension
door
. This movement does not provoke attacks of opportunity. The
esoteric knight cannot bring other creatures with her.

Dimension door has the drawback:

After using this spell, you can’t take any other actions until your
next turn.

Is Step Through Reality merely using Dimension Door as a reference for teleportation mechanics, or would it carry the drawback unique to the spell as well?

## python – Cannot properly dimension a dict of numpy arrays

I have this following data.

column 0 is a text, column 1 is an array of arrays

inabb is my dict name

``````for i in range(len(t_df)):
if t_df.iloc(i)(0) in inabb.keys():
inabb(t_df.iloc(i)(0)) = np.vstack((inabb(t_df.iloc(i)(0)),(t_df.iloc(i)(1))))
else:
inabb(t_df.iloc(i)(0)) = (t_df.iloc(i)(1))
``````

Below is a snippet of the output

``````{'1704_CG08302001.json': array((((0.47488073, 0.11274771, 0.53121686, 0.16514863)),

((0.42959082, 0.5500572 , 0.49034557, 0.60341084)),

((0.16006097, 0.1384718 , 0.22412956, 0.19182546)),

((0.10593408, 0.72917306, 0.16779338, 0.7834794 ))), dtype=float32),
'1704_CG08302002.json': (array(((0.5024965 , 0.5310023 , 0.55993724, 0.58054495)), dtype=float32)),
'1704_CG08302003.json': array((((0.33459264, 0.02700076, 0.38651025, 0.06987424)),

((0.5245891 , 0.03366997, 0.5776113 , 0.07844894))), dtype=float32),
'1704_CG08302004.json': array((((0.16889802, 0.24899009, 0.21750176, 0.2880526 )),

((0.20756009, 0.6319932 , 0.25837308, 0.67391384)),

((0.52127516, 0.07368521, 0.5444724 , 0.11655869)),

((0.40528896, 0.52528584, 0.45499736, 0.5681593 ))), dtype=float32)
``````

What I need is the values to all be of the same array dimensions, either a 3D array, or preferably a (N,4) shape numpy array.

I have tried different code but cannot align the dimensionality. The problem comes when there is no ‘np.vstack()’ and only one array is input, it is not in the same format as the other arrays for array>len(1)

You can see this in the second key value pair below.

## reference request – Dimension of cartesian products

Is there a notion of dimension such that for all Borel sets $$A,Bsubseteqmathbb{R}^{n}$$ we have
$$dim(Atimes B)=dim(A)+dim(B)?$$ For topological, Minkowsky, packing and Hausdorff dimension this is not true. If the answer is no (which I suppose) I like to understand which problems appear, if we try to give such a defintion of dimension.

## Hausdorff dimension and totally disconnected

Prove:
There exists a totally disconnected set $$S ∈ R^2$$ whose Hausdorff dimension is equal to one.

## representation theory – Unfaithful irreps of \$S_n\$ with dimension greater than one

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

## Mean Square Displacement of Self Avoiding Walk in dimension 5 or more

What would be the best detailed written resource to study Mean Square Displacement of Self Avoiding Walk in dimension 5 or more?

## Google Data Studio – “(not set)” value when using Custom Dimension from Google Analytics in Firebase

I’m using Google Analytics in Firebase and I want to make a report in Google Data Studio. I created one custom dimension for an event but in Google Data Studio I only see “(not set)” value for this dimension.

• Waiting 24h (I waited more than 3 days)
• Register more users (now I sent data from 8 devices and I see 8 unique users in the analytics)

Here are two screenshots, the first one is from Custom Definitions page in Firebase Console and the second one is one chart from Google Data Studio.

## linear algebra – What is the dimension of this set?

Consider the set of all linear transformations $$T : mathbb{R}^3 to mathbb{R}^4$$ over $$mathbb{R}$$. What
is the dimension of this set, considered as a vector space over $$mathbb{R}$$ with pointwise operation?

My attempt : consider the linear map $$T: mathbb{R}^3 to mathbb{R}^4$$ define by $$T(x,y,z)=(x+y,2y,2y-x,0)$$

then $$T(1,0,0,0)=(1,0,-1,0) , T(0,1,0)=(1,2,2,0)$$ and $$T(0,0,1)= (0,0,0,0)$$

This implies that dimension of this set will be $$3$$

Am i right/wrong ?

## Find the dimension of the cone of positive definite matrices

Let $$V$$, $$W$$ be the $$n$$, $$m$$ dimensional real vector spaces with scalar product.

What is the dimension of the cones $$P(V)$$, $$P(Votimes W)$$ of positive definite complex operators on $$V$$, $$Votimes W$$ with traces equal to 1?