Skip to content

Commit

Permalink
Main diagonal settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Apr 30, 2024
1 parent a2e7d66 commit 4cd5c20
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,28 @@ const randomizeTypesConfig = () => {
:step="0.1"
:values="randomTypesConfig.LINK_FACTOR_DISTANCE_BOUNDS"
/>
<flag
title="Symmetric"
v-model="randomTypesConfig.LINK_FACTOR_DISTANCE_MATRIX_SYMMETRIC"
style="float: left;"
/>
<flag
title="Extended"
v-model="randomTypesConfig.LINK_FACTOR_DISTANCE_EXTENDED"
style="float: right;"
/>
<div class="grid-wrapper">
<div>
<flag
title="Symmetric"
v-model="randomTypesConfig.LINK_FACTOR_DISTANCE_MATRIX_SYMMETRIC"
/>
</div>
<div>
<flag
title="Ignore self type"
v-model="randomTypesConfig.LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE"
style="text-align: center;"
/>
</div>
<div>
<flag
title="Extended"
v-model="randomTypesConfig.LINK_FACTOR_DISTANCE_EXTENDED"
style="text-align: right;"
/>
</div>
</div>
</div>
</div>

Expand All @@ -202,4 +214,13 @@ const randomizeTypesConfig = () => {
margin-right: 5px;
}
.grid-wrapper {
width: 100%;
display: flex;
flex-wrap: wrap;
}
.grid-wrapper > div {
flex: 1 1;
}
</style>
14 changes: 13 additions & 1 deletion src/lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
createRandomInteger,
createDistributedLinkFactorDistance,
getRandomColor,
randomizeMatrix
randomizeMatrix,
setMatrixMainDiagonal,
setTensorMainDiagonal,
} from "@/lib/helpers";

export function createColors(count: number): Array<ColorVector> {
Expand Down Expand Up @@ -90,6 +92,7 @@ export function createRandomTypesConfig({
LINK_TYPE_MATRIX_SYMMETRIC,
LINK_FACTOR_DISTANCE_MATRIX_SYMMETRIC,
LINK_FACTOR_DISTANCE_EXTENDED,
LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE,
}: RandomTypesConfig): TypesConfig {
const precision = 8;

Expand Down Expand Up @@ -140,6 +143,10 @@ export function createRandomTypesConfig({
precision,
);

if (LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE) {
setMatrixMainDiagonal(linkFactorDistance, 1);
}

let linkFactorDistanceExtended: number[][][] | undefined;

if (LINK_FACTOR_DISTANCE_EXTENDED) {
Expand All @@ -153,6 +160,10 @@ export function createRandomTypesConfig({
precision,
));
}

if (LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE) {
setTensorMainDiagonal(linkFactorDistanceExtended, 1);
}
}

return {
Expand Down Expand Up @@ -194,5 +205,6 @@ export function createDefaultRandomTypesConfig(typesCount: number): RandomTypesC
LINK_TYPE_MATRIX_SYMMETRIC: false,
LINK_FACTOR_DISTANCE_MATRIX_SYMMETRIC: false,
LINK_FACTOR_DISTANCE_EXTENDED: true,
LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE: true,
};
}
3 changes: 2 additions & 1 deletion src/lib/example/variants/2d/random-types-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const TYPES_CONFIG: TypesConfig = createRandomTypesConfig({
LINK_GRAVITY_MATRIX_SYMMETRIC: false,
LINK_TYPE_MATRIX_SYMMETRIC: false,
LINK_FACTOR_DISTANCE_MATRIX_SYMMETRIC: false,
LINK_FACTOR_DISTANCE_EXTENDED: false,
LINK_FACTOR_DISTANCE_EXTENDED: true,
LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE: true,
});
const INITIAL_CONFIG: InitialConfig = create2dBaseInitialConfig();

Expand Down
3 changes: 2 additions & 1 deletion src/lib/example/variants/3d/random-types-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const TYPES_CONFIG: TypesConfig = createRandomTypesConfig({
LINK_GRAVITY_MATRIX_SYMMETRIC: false,
LINK_TYPE_MATRIX_SYMMETRIC: false,
LINK_FACTOR_DISTANCE_MATRIX_SYMMETRIC: false,
LINK_FACTOR_DISTANCE_EXTENDED: false,
LINK_FACTOR_DISTANCE_EXTENDED: true,
LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE: true,
});
const INITIAL_CONFIG: InitialConfig = create3dBaseInitialConfig();

Expand Down
14 changes: 14 additions & 0 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,20 @@ export function concatTensors(lhs: number[][][], rhs: number[][][], defaultValue
return result;
}

export function setMatrixMainDiagonal<T>(matrix: T[][], value: T): T[][] {
for (let i=0; i<matrix.length; ++i) {
matrix[i][i] = value;
}
return matrix;
}

export function setTensorMainDiagonal<T>(tensor: T[][][], value: T): T[][][] {
for (let i=0; i<tensor.length; ++i) {
tensor[i][i][i] = value;
}
return tensor;
}

export function getViewModeConfig(worldConfig: WorldConfig, viewMode?: ViewMode): ViewModeConfig {
return (viewMode ?? worldConfig.VIEW_MODE) === '3d'
? worldConfig.CONFIG_3D
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type RandomTypesConfig = {
LINK_TYPE_MATRIX_SYMMETRIC: boolean;
LINK_FACTOR_DISTANCE_MATRIX_SYMMETRIC: boolean;
LINK_FACTOR_DISTANCE_EXTENDED: boolean;
LINK_FACTOR_DISTANCE_IGNORE_SELF_TYPE: boolean;
};
export type TypesSymmetricConfig = {
GRAVITY_MATRIX_SYMMETRIC: boolean;
Expand Down

0 comments on commit 4cd5c20

Please sign in to comment.