Skip to content

Commit

Permalink
dev(narugo): calculate mean
Browse files Browse the repository at this point in the history
  • Loading branch information
narugo1992 committed Apr 28, 2024
1 parent 65b6065 commit 1a02c85
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions ccip_merge/measure.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import time

import numpy as np
import pandas as pd
from ditk import logging
from imgutils.metrics import ccip_batch_differences, ccip_default_threshold
from scipy.optimize import minimize
from tqdm import tqdm

from .index import get_np_feats
Expand Down Expand Up @@ -35,24 +33,7 @@ def measure_tag_via_func(tag, func):


def ccip_merge_func(embs):
# TODO: just replace your function here!!!
def objective_function(x):
total_similarity = 0
for vector in embs:
total_similarity += np.dot(x, vector) / (np.linalg.norm(x) * np.linalg.norm(vector))
return -total_similarity / embs.shape[0]

initial_guess = np.random.rand(768)
constraints = ({'type': 'eq', 'fun': lambda x: np.linalg.norm(x) - 1.0})
result = minimize(
objective_function, initial_guess,
constraints=constraints,
)

mean_length = np.linalg.norm(embs, axis=1).mean()
best_vec = result.x
best_vec = best_vec * mean_length
return best_vec
return embs.mean(axis=0)


def get_metrics_of_tags(n: int = 100) -> pd.DataFrame:
Expand Down

0 comments on commit 1a02c85

Please sign in to comment.