使用 np.diff() 两次找到 L-Curve 的肘点。但结果并不好

问题描述 投票:0回答:0

我想找到L-Curve的弯头点,我用的代码是这样的,

def findThresholdLCurve(D):
    # 统计所有词语出现的次数并按出现次数降序排序
    Occ = sorted(list(D.values()), reverse=True)
    # 给每个词语一个索引
    word_index = {word: i for i, word in enumerate(D.keys())}

    # calculate the elbow point of the L-Curve
    x = list(range(1, len(D) + 1))
    y = Occ
    ddy = np.diff(np.diff(y)) 

    elbow_index = np.argmax(ddy) + 1
    elbow_coord = (x[elbow_index], y[elbow_index])
    plt.plot(x, y, label='L-curve')
    plt.plot(elbow_coord[0], elbow_coord[1], 'ro', label='Elbow Point') 
    plt.legend()
    plt.show()
    return Occ[elbow_index]

th = findThresholdLCurve(D)

并不总是能得到好的结果。 当

D =  {'A': 0.5966618322834488, 'B': 0.32877029629550597, 'C': 0.5540431299774883}
时,结果是好的。 enter image description here

但是, 当

D = {'vogelnest': 19, 'de': 19, '2008': 19, 'herzog': 19, 'great wall': 8, 'stadium': 19, "bird's": 19, 'nest': 19, 'meuron': 19, 'olympic': 19}
时,结果很糟糕,比如, enter image description here

而且,当

D=OTotal = {'color': 25, 'august': 23, 'summer': 56, '彩色奔跑': 23, 'the color run': 23, 'flickriosapp:filter=nofilter': 31, 'uploaded:by=flickr_mobile': 32, 'architecture': 32, 'film': 33, 'black&white': 9, 'mamiya': 2, '7ii': 2, 'university of technology': 1, '北京工业大学': 1, 'beijing polytechnic university': 1, 'bei gong da': 1, 'beijing university of technology gymnasium': 1, 'gymnasium': 1, 'badminton stadium': 1, 'chen': 1, 'forbidden city': 147, 'winter': 29, 'snap': 24, 'sigma2470': 24, '天坛': 20, 'blackwhite': 1, 'templeofheaven': 4, 'hall of prayer': 1, 'ming': 13, 'temple of heaven': 48, 'ancient': 14, 'angle': 5, 'art': 5, 'asian': 4, 'buddhism': 4, 'building': 33, 'chinese': 9, 'culture': 13, 'dynasty': 13, 'editorial': 23, 'famous': 4, 'heaven': 4, 'heritage': 5, 'historic': 13, 'landmark': 13, 'lot of tourists': 4, 'park': 25, 'symbol': 4, 'temple': 21, 'tourism': 5, 'traditional': 9, 'nanyuan': 1, 'airport': 37, 'zbny': 1, 'nay': 1, 'boeing': 4, '737ng': 2, '737-800': 2, '738': 2, 'b-1750': 1, 'china united airlines': 1, 'cua': 1, 'kn': 1, 'plane': 3, 'planespotter': 3, 'terminal': 5, 'aircraft': 3, 'apron': 1, 'spot': 1, 'cockpit': 1, 'captain': 1, '南苑': 1, '南苑机场': 1, '波音': 3, '波音737': 2, '联航': 1, '中国联合航空': 1, '中国联航': 1, '飞机': 3, '机坪': 1, '机位': 1, '机长': 1, '驾驶舱': 1, 'pilot': 1, '飞行员': 1, '航站楼': 1, 'light': 5, 'night': 23, 'mercedes': 2, 'w124': 2, '200': 3, 'tunerstreet': 1, 'tuner': 1, 'street': 34, 'hutong': 27, 'side street': 13, '胡同': 4, 'beijing planning exhibition hall': 2, 'train attendant': 1, 'cbd': 18, 'beijing cbd': 1, 'fashion': 1, 'girl': 2, 'opposites': 1, 'wait': 1, 'dress': 1, 'crossing': 1, '北站': 1, '八达岭': 5, 'candid': 1, 'back': 1, 'view': 3, 'train': 3, 'lines': 1, 'a55': 1, 'kemily': 1, 'wide angle': 1, '16mm': 1, 'reflections': 1, 'conductor': 1, 'aypwip?': 1, 'officer': 1, 'depth': 1, 'composition': 1, 'tones': 1, '背影': 1, 'sony': 16, 'happy planet': 1, 'asia favorites': 1, 'micro four thirds': 1, '20mm': 9, 'bicycle': 4, 'window': 3, 'colours': 1, 'subway': 2, 'iavrrc': 40, 'theta 360': 3, 'ricoh theta': 3, 'equirectangular': 40, 'china - east asia': 16, 'qing': 9, 'tiananmen square': 11, 'travel destinations': 16, 'architectural': 9, 'capital': 14, 'huge': 3, 'imperial': 10, 'palace': 39, 'people': 24, 'beijing zoo': 1, 'trees': 3, 'china beijing': 1, 'cagèd bird': 1, 'international': 1, 'tiananmen': 22, 'square': 38, 'ye': 1, '鼓楼': 2, 'gulou': 1, 'm': 24, '240': 24, 'summilux': 3, '50': 3, 'drum': 3, 'tower': 11, 'available': 3, 'monument': 14, 'cityscape': 3, 'dark': 2, 'nightlife': 2, 'streetlife': 2, 'cooking': 1, 'cook': 1, 'chef': 1, 'streetfood': 1, 'alleyway': 1, 'face': 2, 'lantern': 1, 'summicron': 21, '28': 21, '钟楼': 1, 'zhonglou': 1, 'bell': 1, 'spring': 23, 'afternoon': 3, 'musician': 1, 'guitarplayer': 1, 'guitar': 1, 'urban': 4, 'sidewalk': 1, 'music': 1, 'great': 8, 'leap': 2, 'brewing': 2, 'beer': 2, 'garden': 17, 'courtryard': 1, 'microbrewery': 2, 'pub': 1, 'bar': 1, 'taproom': 1, 'tap': 1, 'interior': 1, 'blue': 17, 'sky': 17, 'icecream': 1, 'ice': 4, 'cream': 1, 'flowers': 1, 'show': 1, 'display': 1, 'store': 1, 'reflection': 2, 'forbidden': 24, 'museum': 8, 'clear': 7, 'copper': 2, 'vat': 1, '劳动人民文化宫': 1, '太庙': 1, 'hall': 2, 'for': 1, 'worship': 1, 'ancestors': 1, 'ancestral': 1, 'working': 1, "people's": 1, 'cultural': 1, 'taimiao': 1, '201403': 8, 'sanlitun': 3, 'village': 1, 'trb': 3, 'lama': 6, 'buddhist': 6, 'bus': 1, 'transit': 1, 'haze': 3, 'smog': 13, 'pollution': 10, 'bell tower': 2, 'rooftop': 1, 'restaurant': 6, 'construction': 9, 'central business district': 16, 'cctv': 12, 'skyscraper': 20, 'opera': 3, 'egg': 3, 'traffic': 1, 'jam': 1, 'tiny': 1, 'hotel': 39, 'hostel': 1, 'room': 1, 'dreams': 1, "tian'anmen": 3, 'money': 1, '100': 7, 'yuan': 1, 'banknote': 1, 'juxtaposition': 1, 'illusion': 1, 'tour': 1, 'tourist': 7, 'group': 1, 'crane': 1, 'meal': 2, 'food': 10, 'dumplings': 1, 'extension': 1, 'work': 1, 'drum tower': 2, 'poutine': 2, 'québec': 2, 'pekin': 1, 'railway': 1, '1740l': 1, '5dmk2': 1, 'tren': 1, 'vias': 1, 'f10': 1, 'trenbala': 1, 'bullet': 1, 'mamiya 7ii beijing architecture film black&white': 1, 'hawker': 1, 'job': 4, 'bw': 2, 'noiretblanc': 1, '2012': 2, 'paris': 1, 'arch': 3, 'office': 1, 'snow': 2, 'bello': 1, 'landscape': 2, 'sunset': 2, 'zedzap': 1, 'mao': 7, 'mono': 1, 'archway': 2, 'unesco': 7, 'history': 1, 'red': 10, 'old': 9, 'm8': 2, '35mm': 2, 'b&w': 10, 'chine': 3, 'portrait': 2, 'street photography': 4, 'photojournalism': 1, 'nikon d80': 2, 'bicylcette': 1, 'blackandwhite': 3, 'chinese revolution': 1, 'chongwen': 1, 'contax': 1, '645': 1, 'digital': 4, 'phase one': 1, 'p45+': 1, 'houhai': 2, 'colors': 2, 'bluesky': 1, 'fujifilm': 2, 'canonlens': 1, 'gfx100': 2, 'blue sky': 1, 'gf23mmf4': 1, 'sightseeing': 1, 'medium format': 1, "bird's": 25, 'nest': 25, 'olympic': 25, 'stadium': 31, 'vogelnest': 21, 'herzog': 21, 'de': 21, 'meuron': 21, 'hdr': 4, 'ngc': 1, 'soe': 1, 'e-m5': 20, 'om-d': 20, 'olympus': 13, 'olympus om-d e-m5': 20, 'panasonic 20mm f1.7': 8, 'travelling': 20, '45mm': 4, 'chinese chess': 2, 'zuiko 45mm': 4, 'nik': 8, 'silver efex pro 2': 6, 'gǔlóu': 1, '40-150mm': 5, 'gate of heavenly peace': 1, 'zuiko 40-150mm': 5, '天安門廣場': 1, '天安门广场': 1, 'noodle': 3, 'original filter': 1, 'flickriosapp:filter=original': 1, 'iphone 5': 3, 'cameraphone': 3, '2493': 1, 'gavid': 1, 'bowie': 1, 'chan': 1, 'amihan': 1, 'neemic': 1, 'geo-tag approximate': 22, 'lomography x pro 100': 30, 'ricoh ff-1s': 30, 'shunyi district': 15, '南锣鼓巷': 3, '北海公园': 7, '攝影發燒友': 1, 'ninedragonwall': 1, 'dragon': 3, '九龙壁': 1, 'beihaipark': 7, '故宫': 12, 'tree': 2, 'forbiddencity': 11, '紫禁城': 12, 'door': 2, '新疆舞': 2, '灯笼': 2, 'sun': 4, '逆光': 1, 'wall': 9, 'shadow': 1, 'niceshot': 1, '阿发发': 1, 'beijing shi': 9, 'cn': 9, 'fog': 3, 'canon 5d mark ii': 1, 'canon ef 15mm f/2.8': 1, 'forbidden_city': 8, 'fall': 13, 'chaoyang_park': 13, 'autumn': 13, 'instagram app': 13, 'square format': 13, 'iphoneography': 13, 'uploaded:by=instagram': 13, 'mayfair': 2, 'walden': 2, 'x-pro ii': 2, 'amaro': 1, 'lo-fi': 2, 'nashville': 1, 'protest': 6, 'photo': 6, 'surveillance': 1, 'camera': 4, 'lamp': 1, 'post': 1, 'selfie': 2, 'bff': 2, 'friend': 2, 'shanghai': 5, 'pékin': 5, 'ae1': 5, '50mm': 5, 'rokinon': 15, '14mm': 15, 'a7': 15, 'wangfujing': 10, 'nighttime': 11, 'shops': 10, 'long exposure': 1, 'lights': 1, 'headlights': 1, 'jingshan park': 3, 'capture': 3, 'crowd': 4, 'equipment': 3, 'gadget': 3, 'lens': 3, 'male': 3, 'media': 3, 'nature': 5, 'outdoor': 3, 'paparazzi': 3, 'person': 3, 'photograph': 3, 'photographers': 3, 'professional': 3, 'protection': 3, 'scenery': 3, 'seasonal': 3, 'shot': 3, 'shutter': 3, 'technology': 6, 'wildlife': 4, 'zoom': 3, 'birds': 1, 'green': 1, 'arrow nock': 2, 'great wall': 100, 'great wall of china': 3, 'huairou': 2, 'mountain range': 2, 'mutianyu': 2, 'stone material': 2, 'world heritage site': 2, 'hiking': 2, 'horizontal': 2, 'morning': 2, 'outdoors': 2, 'photography': 3, 'region': 2, 'winding': 1, 'grafitti': 1, 'living': 1, 'local': 3, 'quarters': 1, 'street art': 38, 'street life': 2, 'buddha': 2, 'buddha statue': 2, 'dongcheng': 2, 'yonghe': 2, 'yonghe lamasery': 2, 'yonghe temple': 2, 'harmony': 2, 'peace': 2, 'tibet': 2, 'food market': 1, 'market': 7, 'pancakes': 1, 'vendors': 1, 'tuk tuk': 1, 'bike': 7, 'life': 2, 'motorbike': 1, 'transport': 8, 'delivering': 1, 'electric': 6, 'local life': 6, 'street market': 6, 'water': 4, 'detail': 1, 'wide': 1, 'china 2016': 1, 'nikon d810': 1, 'd810': 1, '14-24mm': 1, '14-24': 1, 'nikkor': 1, '365days': 1, '365:2016': 1, '365': 1, 'project 365': 1, '124/365': 1, 'complex': 1, 'vats': 1, 'water vats': 1, 'nanluoguxiang': 1, 'alley': 1, 'center': 1, 'street food': 1, 'andrew jones': 2, 'jones': 2, 'new': 2, 'popular': 2, 'black and white': 1, 'woman': 1, 'outside': 1, 'mad': 1, 'explore': 1, 'faces': 1, 'world': 2, '公园': 16, '祈年殿': 4, 'pathway': 1, 'beamless': 1, '无梁殿': 1, 'bench': 2, '皇穹宇': 1, 'imperial vault of heaven': 1, 'roof': 1, '圜丘坛': 5, 'circular mound': 5, 'altar': 5, 'doorway': 1, 'gate': 1, 'conrad': 38, '康莱德': 38, '酒店': 38, 'indoor': 1, 'swimming': 1, 'pool': 1, '游泳池': 1, 'spa': 1, 'lounge': 18, 'fitness': 2, 'centre': 2, '健身房': 2, '798 art district': 1, '798': 1, 'art galleries': 1, '大裤衩': 2, 'rem koolhaas': 2, 'oma': 2, 'ole scheeren': 2, 'aerial': 1, 'corner': 1, 'river': 1, '蓝': 1, '冰': 1, '冬': 1, '角楼': 1, 'faces of america': 3, '2018': 3, 'wooden': 1, 'qianmen': 1, 'walking': 1, 'f8': 1, 'bmw': 2, 'e34': 2, '520': 1, 'scrapped': 2, '520i': 1, 'guangzhou': 2, 'peugeot': 2, '505': 2, 'station': 2, 'wagon': 2, 'audi': 9, '2.4': 1, 'v6': 1, 'c4': 1, 'faw': 8, 'c3': 4, 'stuffed pig intestines': 1, 'fried': 2, 'mustard': 1, 'chinese cabbage': 1, 'pungent': 1, 'goat offals': 1, 'soup': 1, 'venison skewers': 1, 'fermented bean paste noodles': 1, 'fried dough rings': 1, 'city scape': 7, 'hotel window': 7, 'mooncake': 1, 'festival': 1, '北京科技大学': 3, 'university': 4, 'science': 4, 'event': 5, 'icml14': 5, 'voigtlaender 40/1': 5, '4 nokton': 5, 'panasonic': 5, 'g1': 5, 'panasonic g1': 5, 'voightlaender': 5, 'nokton': 5, 'bridge': 1, 'seventeen': 1, '17': 1, 'kunming': 16, 'lake': 17, 'boat': 1, 'pond': 1, 'mythology': 1, 'holiday': 1, 'foursquare:venue=4d5911b84d9a721edcce3c0e': 1, 'zomerpaleis': 15, 'yiheyuan': 15, 'meer': 15, 'old summer palace': 1, 'yuan ming yuan': 1, 'the gardens of perfect brightness': 1, 'unesco world heritage site': 4, '天壇': 1, 'gardens of nurtured harmony': 3, 'kunming lake': 3, 'longevity hill': 3, 'summer palace': 5, '昆明湖': 3, '頤和園': 3, 'silver efx pro 2': 1, '12-50mm': 2, 'zuiko 12-50mm': 2, 'sutro': 1, 'flower': 3, 'earlybird': 1, 'haidian': 1, 'xijiao': 1, 'zbbb': 1, 'b-4080': 1, 'plaaf': 1, 'pla': 1, 'air force': 1, '海淀': 1, '西郊': 1, '西郊机场': 1, '空军': 1, '中国空军': 1, 'blossoms': 1, 'cherry': 1, 'national': 4, 'bad': 8, 'air': 8, 'cube': 1, 'low light': 2, 'olympic forest park': 1, 'nik collection': 1, 'beijing national stadium': 6, "bird's nest": 6, 'olympic green': 6, 'olympic park': 6, "people's republic of china": 4, '北京奧林匹克公園': 6, '国家体育场': 6, '鸟巢': 6, 'photosynth': 2, 'snapseed': 2, 'panorama': 2, 'water cube': 2, '国家游泳中心': 2, '水立方': 2, '798 art zone': 37, 'dashanzi art district': 37, 'chaoyang district of beijing': 37, 'graffiti art': 37, 'vr': 37, 'virtual reality': 37, '360 panorama': 37, 'google cardboard': 37, 'běijīng': 3, 'shǒudū': 3, 'guójì': 3, 'jīchǎng': 3, 'beijing capital airport': 3, 'long corridor': 1, 'creative': 1, 'crystal ball': 1, 'glass ball': 1, 'hands': 1, 'holding': 1, '3': 3, 'chapter': 1, '餐厅': 1, 'lobby': 1, 'reception': 2, 'bathroom': 10, 'amenity': 5, 'bathtub': 3, 'refinery': 1, '炒饭': 1, '炒面': 1, 'rice': 1, 'breakfast': 13, 'charcuterie': 1, 'cold cut': 1, 'fruit': 1, 'shower': 1, '沐浴室': 1, 'shanghai tang': 1, '上海滩': 1, 'bedroom': 3, 'premium': 3, 'closet': 1, 'wardrobe': 1, 'sausage': 1, 'sirloin': 1, 'vegetable': 1, 'cabbage': 1, 'pork': 1, 'salad': 1, '沙律': 1, 'delta airlines': 2, '达美航空': 2, 'airbus': 1, 'a350': 1, 'a350-900': 1, 'pek': 29, '机场': 29, 'terminal 2': 28, '777': 1, '777-300er': 1, '印尼航空': 1, 'garuda indonesia': 1, 'bgs': 17, 'premier': 17, 'sky priority': 1, 'sky team': 1, 'departure': 4, 'flying': 1, '飞行': 1, 'bread': 1, 'sandwich': 1, '三文治': 1, 'instant': 1, 'dumpling': 1, '烧卖': 1, 'dim sum': 1, '点心': 1, 'coffee': 1, 'machine': 1, 'newspaper': 1, 'magazine': 1, 'invitation': 1, 'card': 1, 'entrance': 1, 'check in': 1, 'chaoyang': 1, 'shunyi': 1, 'beijing capital international airport': 1, 'zbaa': 1, 'air china': 1, 'ca': 1, 'cca': 1, '747-400': 1, '744': 1, 'b-2472': 1, 'air force one': 1, 'af1': 1, 'pratt & whitney': 1, 'pw': 1, '朝阳': 1, '顺义': 1, '北京首都国际机场': 1, '国航': 1, '中国国际航空': 1, '擦航': 1, '波音747': 1, '空军一号': 1, '雾霾': 1, '霾': 1, '普惠': 1, 'pw4056': 1, '专机': 1, 'changping': 1, 'political': 1, 'law': 1, 'campus': 1, 'cupl': 1, 'education': 1, 'nikon d90': 1, 'achitecture': 1, 'corn': 1, 'disneyland': 1, 'disney': 1, 'amusement': 1, 'abandoned': 4, 'farm': 1, 'asia beijing abondoned disneyland architecture hdr park sunset u': 1, 'asia beijing abondoned disneyland architecture hdr park sunset urbex': 1, 'huai rou': 14, 'grande muraille': 13, 'run down': 3, 'derelict': 3, 'crumbling': 3, 'mutainyu': 66, 'astonishing': 66, 'v8': 2, 'lang': 2, 'miyun': 2, 'badaling': 4, 'yanqing': 4, 'monochrome': 1, 'black': 1, 'white': 1, 'arrival': 1, 'central': 1, 'facade': 1, 'rail': 1, 'town': 1, 'train station': 1, 'transportation': 1, '1992-1999': 1, 'jinshanling': 1, 'wonder': 1, 'climb': 1}

结果就像, enter image description here

当D的尺寸变大时,结果会像, enter image description here

第三种情况是比较常见的L-Curve,但是结果不在弯头,那么我的代码怎么改呢?或者,是否有其他方法可以找到 L 曲线的弯头点?

python point
© www.soinside.com 2019 - 2024. All rights reserved.